15. Kth Smallest Element in BST
β GFG solution to the Kth Smallest Element in BST problem: find the kth smallest element in a binary search tree using iterative inorder traversal with stack. π
π§© Problem Description
π Examples
Example 1
Input: root = [20, 8, 22, 4, 12, N, N, N, N, 10, 14], k = 3
Output: 10
Explanation: The inorder traversal of the BST is [4, 8, 10, 12, 14, 20, 22].
The 3rd smallest element is 10.Example 2
Input: root = [2, 1, 3], k = 5
Output: -1
Explanation: There is no 5th smallest element in the BST as the size of BST is 3.π Constraints
β
My Approach
Iterative Stack-Based Inorder Traversal
π Time and Auxiliary Space Complexity
βοΈ Code (C)
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated