You are given the root of a binary search tree (BST) and an integer k.
Return the kth smallest value in the tree (counting starts from 1).
Input: root = [4,2,6,1,3,5,7], k = 4
Output: 4
Explanation:
The tree’s values in sorted order are [1,2,3,4,5,6,7]. The 4th smallest number is 4.
Input: root = [2,1,3], k = 2
Output: 2
Explanation:
Sorted order is [1,2,3]. The 2nd smallest number is 2.
Input: root = [7,3,9,2,5,8,10], k = 5
Output: 8
Explanation:
Sorted order is [2,3,5,7,8,9,10]. The 5th smallest number is 8.
Accepted:
Submission: