Question
Given theĀ
rootĀ of a binary search tree, and an integerĀk, returnĀ theĀkthĀ smallest value (1-indexed) of all the values of the nodes in the tree.
This is a tree question.
Idea(s)
- Depth First Search solution
- The key here is to notice that inorder traversal essentially sorts the BST
- Then just return the k-1th element in the result array