All problems
LWW Map Merge
Problem
Merge two last-write-wins maps.
Each map stores key to [value, timestamp]. For every key the entry with the larger timestamp wins, and ties keep the value from a. Keys are strings.
Return the merged map.
Hint
On a timestamp tie the first map's value is kept for determinism.
Test cases
case 1
in: [{"x":["a",1],"y":["b",3]},{"x":["c",2],"z":["d",1]}]
expected: {"x":["c",2],"y":["b",3],"z":["d",1]}
case 2
in: [{},{"k":["v",1]}]
expected: {"k":["v",1]}
case 3
in: [{"k":["a",5]},{"k":["b",5]}]
expected: {"k":["a",5]}
case 4
in: [{},{}]
expected: {}
Starter codePython
def lww_merge(a, b):
# Your code here
pass4 test cases · run your code against them in the editor