Kth Smallest in Binary Search Tree
Problem Statement
Given the root of a binary search tree (BST) and an integer
kkthRules and Constraints
- The BST is not necessarily balanced.
- The number of nodes in the BST will be in the range .
[1, 10^4] - The values of the nodes will be in the range .
[1, 10^5] - The input BST is guaranteed to be a valid binary search tree.
- You must return the smallest element.
kth
Note: The solution should be efficient in terms of time complexity, as the input values are relatively large.
Example
Input: {"root":[3,1,4,null,2],"k":1} Output: 1
CompaniesAmazon
JavaScript
Login to write code
Solve problems, verify your skills, and earn XP.