Back to course home
0% completed
Solution: Merge Similar Items
Problem Statement
Given two 2D arrays of item-value pairs, named items1
and items2
.
- item[i] = [value<sub>i</sub>, weight<sub>i</sub>], where each value<sub>i</sub> in these arrays is unique within its own array and is paired with a weight<sub>i</sub>.
Combine these arrays such that if a value appears in both, its weights are summed up. The final merged array should be sorted based on the value<sub>i</sub>.
Examples
- Example 1:
- Input:
items1 = [[1,2],[4,3]]
,items2 = [[2,1],[4,3],[3,4]]
- Expected Output:
[[1,2],[2,1],[3,4],[4,6]]
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible