Problem · Tree
Binary Search Tree Iterator
Learn this problemProblem statement
Process next and hasNext operations against one ascending BST iterator. next returns the next smallest value; hasNext reports whether another value remains. Return each result as a string in operation order.
Function
runBSTIterator(root: TreeNode, operations: String[]) → String[]Examples
Example 1
root = [7,3,15,null,null,9,20]operations = ["next","next","hasNext","next","hasNext"]return = ["3","7","true","9","true"]The iterator yields the inorder sequence and keeps its position between operations.
Constraints
- The BST contains between
1and10000unique nodes. - Every
nextoperation is valid. - There are at most
20000operations.
More Atlassian problems
- Planning ProductionOA · Seen Feb 2025
- K-Means ClusteringOA · Seen Feb 2025
- Minimum Sorted Erasure OperationsOA · Seen Jun 2024
- Count Analogous ArraysOA · Seen Mar 2024
- Get Maximum ScoreOA · Seen Mar 2024
- Better Compression 🦀OA · Seen Mar 2024
- Romanizer 🐡OA · Seen Mar 2024
- Flower Bouquets 💐OA · Seen Mar 2024