Back to course home
0% completed
Vote For New Content
Solution: Kth Smallest Element in a BST
Problem Statement
Given a root
node of the Binary Search Tree (BST) and integer 'k'. Return the Kth smallest element among all node values of the binary tree.
Examples:
-
Example 1:
Input:8 / \ 3 10 / \ \ 1 6 14 / \ / 4 7 13
k = 4
Expected Output: 6
Justification: The in-order traversal of the tree is [1, 3, 4, 6, 7, 8, 10, 13, 14]. The 4th element in this sequence is 6. -
Example 2:
Input:5 / \ 2 6 / 1
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page