Kth Smallest Element in a BST
Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.

30:00

Kth Smallest Element in a BST
medium
Topics
Companies

Given the root of a binary search tree, and an integer k, return the kth smallest value (1-indexed) of all the values of the nodes in the tree.

Example 1:
Input: {"root":[3,1,4,null,2],"k":1}
Output: 1
Constraints:
  • The number of nodes is nn.

  • 1kn1041 \leq k \leq n \leq 10^4

  • 0Node.val1040 \leq \text{Node.val} \leq 10^4

Input
arr ={"root":[3,1,4,null,2],"k":1}

Init stack

3

1

4

2

Variables
No variables to display
DepthFunction Call
Stack empty
0/8