Verified interview challenge
Build a database with nested transactions
Implement an in-memory database whose transactions can contain further transactions.
Unlock with Full AccessThe challenge
Process a sequence of database commands while keeping track of the state visible at each transaction level. Your program must handle reads, writes, deletions and value counts as transactions are committed or rolled back. Changes in an inner transaction need to interact correctly with the surrounding state.
What you'll practise
Transaction boundaries
Track nested changes and the effect of committing or rolling them back.
Visible database state
Keep reads and deletions consistent across transaction levels.
Value counts
Maintain correct counts as keys change and earlier states are restored.
solution.pyPython 3.13
import sys
def main():
# Read input and print your result
passTest cases
Run your code to see results.
Full instructions, starter code and test cases included with Full Access.