Key-Value Store with Nested Transactions
Updated
Problem statement
Implement an in-memory key-value store that processes a sequence of operations.
Each operation is a string array in one of these forms:
["SET", key, value]: assignvaluetokeyin the current transaction, or in the base store when no transaction is active.["GET", key]: read the value visible in the current transaction context. Append that value to the result, or append"NULL"when the key does not exist.["DELETE", key]: makekeyabsent in the current transaction context.["BEGIN"]: begin a new transaction nested inside the current context.["COMMIT"]: commit the innermost transaction into its parent context. When it is the outermost transaction, commit into the base store.["ROLLBACK"]: discard the innermost transaction.
Only GET operations produce output. Return their results in operation order.
A deletion inside a transaction must hide an older value without deleting that older value from the parent context; rolling back must therefore reveal the parent value again.
Function
processOperations(operations: String[][]) → String[]Examples
Example 1
operations = [["SET","theme","light"],["GET","theme"],["BEGIN"],["SET","theme","dark"],["GET","theme"],["ROLLBACK"],["GET","theme"]]return = ["light","dark","light"]The transaction temporarily changes theme to "dark". Rolling it back reveals the base value "light".
Example 2
operations = [["SET","a","1"],["BEGIN"],["DELETE","a"],["GET","a"],["BEGIN"],["SET","a","2"],["COMMIT"],["GET","a"],["ROLLBACK"],["GET","a"]]return = ["NULL","2","1"]The outer transaction hides a. The nested transaction restores it as "2" and commits that change into the outer transaction. Rolling back the outer transaction restores the base value "1".
Example 3
operations = [["BEGIN"],["SET","x","7"],["BEGIN"],["SET","y","8"],["COMMIT"],["COMMIT"],["GET","x"],["GET","y"],["GET","z"]]return = ["7","8","NULL"]The inner commit merges y into its parent transaction. The outer commit then persists both keys to the base store.
Constraints
1 <= operations.length <= 10^5.- Keys and values are non-empty strings containing at most
50printable ASCII characters. - Every operation has one of the documented forms.
- Every
COMMITandROLLBACKhas an active transaction. - The transaction nesting depth is at most
10^5.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
- Transactional In-Memory RedisHashiCorp · ONSITE INTERVIEWHashiCorp interview questions
- Nested Recipe Cart TransactionsDecagon · PHONE SCREENDecagon interview questions
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
- Mutable Points in a Hash Set and a ListMillennium · PHONE SCREENMillennium interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
Interview reports that mention this question
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling No-Level Screens and Loops: 18 Experiences (Part 4 of 6)
- Rippling No-Level Coding Screens: 37 Experiences (Part 3 of 6)
- Rippling SWE Interviews, No Level: 156 Experiences (Part 1 of 6)
- Rippling L7 and Senior Onsites: 18 Experiences (Part 7 of 12)
- Rippling SDE-1 and SDE-2 Onsites: 14 Experiences (Part 9 of 12)