Merge Similar Items
Each item of items1 and items2 is [value, weight]. Within one list the values are all different, but the two lists may share values.
Combine the two lists: for every value that appears in either list, add its weights from both. Return the result as [value, total_weight] pairs sorted by value.
Example 1
items1 [[1,1],[4,5],[3,8]]
items2 [[3,1],[1,5]]
returns [[1,6],[3,9],[4,5]]
Value 1: 1+5 = 6; value 3: 8+1 = 9; value 4: 5.
Constraints
0 <= len(items1), len(items2) <= 150 <= value, weight <= 20
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.