Binary Search Tree Iterator
Updated
Problem 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 Online Assessment questions
- 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
- Binary Tree Level Order TraversalOA · Seen Nov 2023
- Design HashMapOA · Seen Nov 2023
Similar questions at other companies
- Lazy Binary Tree Inorder IteratorApple · PHONE SCREEN
- Evaluate an Addition and Subtraction TreeExpedia · ONSITE INTERVIEW
- Layer History with Batch Undo and RedoFigma · OA · PHONE SCREEN
- Undo/Redo Timeline State EngineKickdrum · OA
- Nested In-Memory Database TransactionsDRW · OA
- Adding Stack 2.0IMC Trading · OA
- Min StackShopify · OA
- Text Editor OperationsMicrosoft · OA
- Preorder, Inorder and Postorder of a Binary TreeCapital One · OA · ONSITE INTERVIEW
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW