52. Kth Smallest Element in a BST

Return the k-th smallest value (1-indexed) in a binary search tree.

Example 1

Input: root = [3,1,4,null,2], k = 1
Output: 1

Example 2

Input: root = [5,3,6,2,4,null,null,1], k = 3
Output: 3
Hint 1

In-order traversal of a BST visits values in sorted order.

Hint 2

Stop as soon as you have visited k nodes.

TreeBST