Implement BST Iterator and Ticket Queue
Company: Meta
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates understanding of binary search tree traversal and iterator design with amortized time and space analysis, as well as dynamic priority-queue design for maintaining ordered tickets with severity, recency, and tie-breaking rules.
BST Iterator Operation Simulation
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([7,3,15,None,None,9,20], ["next","next","hasNext","next","hasNext","next","hasNext"] )
Expected Output: [3, 7, True, 9, True, 15, True]
Explanation: Iterator visits values in ascending order.
Input: ([], ["hasNext"])
Expected Output: [False]
Explanation: Empty tree.
Input: ([2,1,3], ["hasNext","next","next","next","hasNext"])
Expected Output: [True, 1, 2, 3, False]
Explanation: Full traversal.
Hints
- Pick a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.
Prioritized Ticket Queue with Updates
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([['get_top_ticket'], ['upsert', 10, 'low', 5], ['upsert', 2, 'high', 3], ['get_top_ticket'], ['upsert', 10, 'high', 9], ['get_top_ticket']],)
Expected Output: [-1, None, None, 2, None, 10]
Explanation: Updates change priority.
Input: ([['upsert', 2, 'medium', 7], ['upsert', 1, 'medium', 7], ['get_top_ticket']],)
Expected Output: [None, None, 1]
Explanation: Tie breaks by smaller id.
Hints
- Pick a representation that makes the requested operation direct.
- Handle empty inputs and boundary cases first.