Given the root of a BST and integer k, return the kth smallest value (1-indexed) of all values in the BST.
Inorder traversal of a BST gives values in sorted order. Do iterative inorder traversal and return the kth element visited.
- Use iterative inorder with a stack.
- Push nodes left as far as possible.
- Pop a node, decrement k. If k==0, return node.val.
- Move to right subtree.
- Time Complexity: O(H + k)
- Space Complexity: O(H)