Nested In-Memory Database Transactions
Updated
Problem statement
Implement an in-memory database with a permanent store and a stack of active transactions. Process the finite array operations from left to right and return one output string for every operation.
Each operation has one of these forms:
BEGIN: push an empty transaction and returnOK.SET key value: write into the newest active transaction and returnOK. If no transaction is active, do not change state and returnERROR.GET key: search active transactions from newest to oldest, then the permanent store. Return the first value found, orNOT_FOUND.COUNT: return the number of keys in the permanent store as a decimal string. Uncommitted keys do not count.ROLLBACK: discard only the newest active transaction and returnOK. If no transaction is active, returnERROR.COMMIT: apply all active transactions to the permanent store from oldest to newest, clear the transaction stack, and returnOK. If no transaction is active, returnERROR.
The database starts with an empty permanent store and no active transaction.
Function
runDatabaseSimulator(operations: String[]) → String[]Examples
Example 1
operations = ["COUNT","BEGIN","SET a 1","GET a","COUNT","COMMIT","COUNT","GET a"]return = ["0","OK","OK","1","0","OK","1","1"]The uncommitted key is readable through GET but does not affect COUNT. After COMMIT, it becomes permanent.
Example 2
operations = ["BEGIN","SET x outer","BEGIN","SET x inner","GET x","ROLLBACK","GET x","COMMIT","GET x"]return = ["OK","OK","OK","OK","inner","OK","outer","OK","outer"]The inner value shadows the outer value until the inner transaction is rolled back. Committing then makes the outer value permanent.
Constraints
- Every operation follows one of the documented command forms.
- Keys and values are non-empty and contain no whitespace.
- A stored value is never the reserved result token
NOT_FOUND.
More DRW Online Assessment questions
- Count Balanced Nodes in a Rooted TreeOA · Seen Sep 2026
- Largest Number With Even Digit FrequenciesOA · Seen Sep 2026
- Shortest Path Around Rectangular ObstaclesOA · Seen Sep 2026
- 2020 Account Balance with Monthly Card FeesOA · Seen Aug 2026
- Password Requirement CheckOA · Seen Aug 2026
- Remove Excess Consecutive CharactersOA · Seen Aug 2026
- Last Round for Each PlayerOA · Seen Jul 2026
- Shortest Compressed Length After RemovalOA · Seen Jul 2026
- Doctor Appointment Slot AssignmentOA · Seen Jul 2026
- Maximum Even-Sum Neighboring PairsOA · Seen Jul 2026
Similar questions at other companies
- Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
- KV Store with Nested TransactionsApplied Intuition · PHONE SCREEN · ONSITE INTERVIEWApplied Intuition interview questions
- In-Memory Database with Transactions and SavepointsNextdoor · PHONE SCREENNextdoor interview questions
- Nested Transaction Key-Value StorexAI · ONSITE INTERVIEWxAI interview questions
- Transactional In-Memory RedisHashiCorp · ONSITE INTERVIEWHashiCorp interview questions
- Key-Value Store with Nested TransactionsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Maximum Frequency StackAmazon · PHONE SCREEN
- Nested Recipe Cart TransactionsDecagon · PHONE SCREENDecagon interview questions
- Maximum Frequency StackKalshi · PHONE SCREEN
- Maximum Frequency StackBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions