Snapshot Set Iterator
Updated
Problem statement
Process a finite sequence of operations on an insertion-ordered set and its snapshot iterators.
Each operation is one of:
["ADD", value]: addvaluewhen absent. Adding an existing value does nothing.["REMOVE", value]: removevaluewhen present. Removing a missing value does nothing. A removed value that is later added again appears at the end of the insertion order.["ITERATOR", iteratorId]: create a new iterator over a snapshot of the current values in insertion order.["NEXT", iteratorId]: return the next value from that iterator, or"<END>"when it is exhausted.
Mutations after an iterator is created never change that iterator's snapshot. Return one string for every NEXT operation, in operation order.
Function
runSnapshotSet(operations: String[][]) → String[]Examples
Example 1
operations = [["ADD","a"],["ADD","b"],["ITERATOR","it"],["ADD","c"],["REMOVE","a"],["NEXT","it"],["NEXT","it"],["NEXT","it"]]return = ["a","b","<END>"]The iterator snapshots [a,b]. Adding c and removing a afterward do not affect it, so its two values are followed by the exhaustion sentinel.
Example 2
operations = [["ADD","x"],["ADD","y"],["ADD","x"],["REMOVE","x"],["ADD","x"],["REMOVE","z"],["ITERATOR","s"],["NEXT","s"],["NEXT","s"],["NEXT","s"]]return = ["y","x","<END>"]The duplicate add and missing remove are no-ops. Removing and re-adding x moves it behind y in the current insertion order.
Constraints
1 <= operations.length <= 10000- Every operation has a valid name and arity.
- Values and iterator IDs are non-empty strings.
- Values are never equal to
"<END>". - Every iterator ID is created exactly once before its first
NEXT.
More Databricks Phone Screen questions
- Rolling Hit CounterPHONE SCREEN · Seen Nov 2026
- Minimize CommuteOA · PHONE SCREEN · Seen Oct 2026
- Top-K Values per Key in MapReducePHONE SCREEN · Seen Oct 2026
- Customer Revenue with Direct ReferralsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- File Encryption Tree OptimizationPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Encrypted File Count and Minimum TimePHONE SCREEN · Seen Sep 2026
- Circuit Breaker Database FailoverPHONE SCREEN · Seen Aug 2026
- Find First Anagram IndexPHONE SCREEN · Seen Aug 2026
- Ordered IP FirewallPHONE SCREEN · Seen Aug 2026
- Key-Value Store GET and PUT QPSPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- In-Memory Vault File SystemHarvey · ONSITE INTERVIEWHarvey interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Hash Map with Separate ChainingApplied Intuition · ONSITE INTERVIEWApplied Intuition interview questions
- Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Corporation Reporting LinesMicrosoft · PHONE SCREENMicrosoft interview questions