Skip to content
DeepForgeby svx
All problems
MediumData Structuresds-279

Read-Your-Writes Queue

Problem

Simulate read-your-writes consistency for a session.

operations contains "write" (keys[i] = values[i], buffered), "flush" (publish buffered writes to the store), or "read" (record the buffered value for keys[i] if present, else the stored value or None).

Return the list of recorded results (None for write and flush).

Hint

A session's buffered writes shadow the committed store until flushed.

Test cases

case 1
in: [["write","read","flush","write","read"],["a","a","","a","a"],[1,0,0,2,0]]
expected: [null,1,null,null,2]
case 2
in: [["read"],["x"],[0]]
expected: [null]
case 3
in: [["write","flush","read"],["k","","k"],[5,0,0]]
expected: [null,null,5]
case 4
in: [["write","write","read","flush","read"],["k","k","k","","k"],[1,2,0,0,0]]
expected: [null,null,2,null,2]
Starter codePython
def ryw_queue(operations, keys, values):
    # Your code here
    pass

4 test cases · run your code against them in the editor