Problem · Design
Durable Data Writer
Learn this problemProblem statement
Simulate a durable record writer by processing a finite operation sequence. The writer starts in the running state with empty pending and durable storage.
Each operation is one of:
["WRITE", record]: appendrecordto the in-memory pending buffer.["FLUSH"]: atomically append every pending record to durable storage, preserving order, then clear the pending buffer. Flushing an empty buffer does nothing.["CRASH"]: discard only pending records and enter the crashed state. Durable records remain unchanged.["RECOVER"]: leave the crashed state with the durable records intact and an empty pending buffer.["READ"]: return a snapshot of the durable records. Pending records are not visible.
After CRASH, the next operation is RECOVER. Return one string array for every READ operation, in operation order. Duplicate records are preserved.
Function
simulateDurableWriter(operations: String[][]) → String[][]Examples
Example 1
operations = [["WRITE","A"],["WRITE","B"],["READ"],["FLUSH"],["READ"]]return = [[],["A","B"]]The first read sees no durable records because both writes are pending. After the flush, both records are durable and visible in order.
Example 2
operations = [["WRITE","a"],["FLUSH"],["WRITE","b"],["CRASH"],["RECOVER"],["READ"],["WRITE","c"],["FLUSH"],["READ"]]return = [["a"],["a","c"]]Record a survives because it was flushed. Pending record b is lost in the crash. After recovery, c is written and flushed after a.
Constraints
1 <= operations.length <= 10000- Every operation has a valid name and arity.
- Every record is a non-empty string of at most
100characters. - The total number of
WRITEoperations is at most5000. - After each
CRASH, the next operation isRECOVER.
More Databricks problems
- Blocking Keyed Cache with Waiting ReadersONSITE INTERVIEW · Seen Jul 2026
- Rectangular K-in-a-RowONSITE INTERVIEW · Seen Jul 2026
- Snapshot Set IteratorPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Find First Anagram IndexPHONE SCREEN · Seen Apr 2026
- Minimize CommuteOA · Seen Apr 2026
- Difference Between Sums of PositionsOA · Seen Sep 2024
- Longest Common Prefix of Number PairsOA · Seen Sep 2024
- Subarray CountingOA · Seen Sep 2024