Given the root of a binary search tree and an integer k, return the value of the kth smallest node in the tree. Pattern focus: Inorder Gives Sorted Sequence. An inorder traversal of a BST visits values in ascending order, so the kth visited node is the answer.
root = binary tree root, k = 1-indexed order statistic
kth smallest value in the BST
Example 1:
Input:
root = [3,1,4,null,2] k = 1
Output:
1
Explanation:
The smallest value in the BST is 1.
Example 2:
Input:
root = [3,1,4,null,2] k = 3
Output:
3
Explanation:
Inorder order is [1,2,3,4], so the 3rd value is 3.