Kth Smallest Element in BST

Medium
Trees Tree DFS BST

Find kth smallest element in BST given as level-order.

Constraints

1 ≤ k ≤ n ≤ 10^4

Examples

Example 1:
Input: 3 1 4 null 2 1
Output: 1
Example 2:
Input: 5 3 6 2 4 null null 1 3
Output: 3
▲ Console

Install Talent Arabia

Get instant access to jobs and career tools on your device.