Kth Smallest Element in a BST
Find the k-th smallest value in a BST.
Because an inorder traversal of a BST returns values in ascending order, the answer is the kth visited node in that traversal.
Examples
Input: [[3,1,4,null,2],1]
Output: 1
Input: [[5,3,6,2,4,null,null,1],3]
Output: 3
Hints
Inorder traversal gives sorted order.
Use a counter to stop at kth node.
Could also use BST property to prune (count nodes in subtrees).
Related Problems
Kth Smallest Element in a BST
Find the k-th smallest value in a BST.