Skip to content
DeepForgeby svx
All problems
MediumData Structuresds-293

Delta CRDT Compression

Problem

Compress a list of CRDT updates to the latest version per key.

updates is a list of [key, value, version]. Keep only the update with the largest version for each key.

Return [key, value, version] triples sorted by key.

Hint

Version numbers give a total order per key, so the maximum version wins.

Test cases

case 1
in: [[["a",1,1],["b",2,1],["a",3,2]]]
expected: [["a",3,2],["b",2,1]]
case 2
in: [[]]
expected: []
case 3
in: [[["x",5,7]]]
expected: [["x",5,7]]
case 4
in: [[["k",1,2],["k",1,1]]]
expected: [["k",1,2]]
Starter codePython
def delta_compress(updates):
    # Your code here
    pass

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