Nested Transaction Key-Value Store
Updated
Problem statement
Process operations against an initially empty string key-value store.
["SET", key, value]writes in the current transaction, or directly to the base store when no transaction is open.["GET", key]returns the most recent visible value, orNULLwhen absent.["BEGIN"]opens a transaction nested inside the current one.["COMMIT"]commits the innermost transaction into its parent, or into the base store when it is outermost.["ROLLBACK"]discards the innermost transaction.
An inner commit is not durable beyond its parent: if that parent is later rolled back, the inner changes disappear too. Return all GET outputs in order.
Function
runNestedTransactions(operations: String[][]) → String[]Examples
Example 1
operations = [["SET","x","1"],["BEGIN"],["SET","x","2"],["BEGIN"],["SET","x","3"],["COMMIT"],["GET","x"],["ROLLBACK"],["GET","x"]]return = ["3","1"]The inner commit makes x = 3 visible in its parent. Rolling back that parent then restores the base value x = 1.
Example 2
operations = [["BEGIN"],["SET","a","outer"],["BEGIN"],["SET","b","inner"],["GET","a"],["GET","b"],["COMMIT"],["COMMIT"],["GET","b"],["GET","missing"]]return = ["outer","inner","inner","NULL"]The inner transaction reads its parent's a value. Committing both levels makes b visible in the base store.
Constraints
1 <= operations.length <= 200000.- Every operation has the exact arity shown above.
COMMITandROLLBACKoccur only while a transaction is open.- Keys and values are non-empty ASCII strings; values are never
NULL. - The total length of all keys and values is at most
2000000. - Transaction nesting depth is at most
100000.
More xAI interview questions
- Live Top-K Spaces by Active UsersONSITE INTERVIEW · Seen Jan 2026
- Total Active Time by SpaceONSITE INTERVIEW · Seen Jan 2026
- Dynamic Batch Decode TraceONSITE INTERVIEW · Seen Dec 2025
- Weighted LRU CacheONSITE INTERVIEW · Seen Oct 2025
- LFU CacheONSITE INTERVIEW · Seen Sep 2025
- Cached Lazy Token BucketsONSITE INTERVIEW · Seen Sep 2025
- Least Recently Used CacheONSITE INTERVIEW · Seen Jun 2025
- Resumable List IteratorPHONE SCREEN · Seen Apr 2026
- Earliest Dataset Readiness in a PipelinePHONE SCREEN · Seen Mar 2026
- Largest Plus SignOA · Seen May 2025
Similar questions at other companies
- KV Store with Nested TransactionsApplied Intuition · PHONE SCREEN · ONSITE INTERVIEWApplied Intuition interview questions
- Transactional In-Memory RedisHashiCorp · ONSITE INTERVIEWHashiCorp interview questions
- Key-Value Store with Nested TransactionsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Maximum Frequency StackBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
- In-Memory Database with Transactions and SavepointsNextdoor · PHONE SCREENNextdoor interview questions
- Nested In-Memory Database TransactionsDRW · OADRW interview questions
- Maximum Frequency StackAmazon · PHONE SCREEN
- Nested Recipe Cart TransactionsDecagon · PHONE SCREENDecagon interview questions
- Maximum Frequency StackKalshi · PHONE SCREEN