Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Kth Smallest Element in a BST

Medium
treebinary-search-treedfs

Given a BST and an integer k, return the k-th smallest value (1-indexed).

Input

  • Line 1: the BST in level order
  • Line 2: integer k

Output: the k-th smallest value.

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

Constraints

  • 1 ≤ k ≤ nodes ≤ 10^4
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.