Dodomeki
Sign in

75. Kth Smallest in a BST

Medium

Given a BST and an integer k, return the kth smallest value, counting k from 1. The tree values are distinct and k is valid.

Example 1
Input: raiz = [7, 3, 10, 1, 5, 9, 12], k = 4
Output: 7
Example 2
Input: raiz = [2, 1, 3], k = 1
Output: 1
Constraints
  • 1 <= k <= number of nodes.
  • The tree is a valid BST with distinct values.
TreesBinary search treeDFS
Caso 1
raiz =
[7,3,10,1,5,9,12]
k =
4
Expected =
7
Caso 2
raiz =
[2,1,3]
k =
1
Expected =
1

Run checks these 2 cases. Submit runs all 6, including hidden ones.