9.Kth Smallest Element in a BST
Example 1:
Input: root = [3,1,4,null,2], k = 1
3
/ \
1 4
\
2
Output: 1
Example 2:
Input: root = [5,3,6,2,4,null,null,1], k = 3
5
/ \
3 6
/ \
2 4
/
1
Output: 3Solution I :(Using Inorder Traversal)
Time Complexity: O(n), Space Complexity: O(n)
Solution II: (Using Traversal)
Last updated
Was this helpful?