Practice Merge Two 2D Arrays by Summing Values
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Each entry of nums1 and nums2 is [id, value]; IDs are unique within each input and sorted increasingly. Return one entry for every ID appearing in either input, summing its values across both inputs and treating a missing value as zero. Sort the result by increasing ID.
Source: Merge Two 2D Arrays by Summing Values on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums1 = [[1,2],[2,3],[4,5]], nums2 = [[1,4],[3,2],[4,1]]
Output
[[1,6],[2,3],[3,2],[4,6]]
# Example 2
Input
nums1 = [[2,4],[3,6],[5,5]], nums2 = [[1,3],[4,3]]
Output
[[1,3],[2,4],[3,6],[4,3],[5,5]]
Constraints
1 <= nums1.length, nums2.length <= 200
nums1[i].length == nums2[j].length == 2
1 <= idi, vali <= 1000
Both arrays contain unique ids.
Both arrays are in strictly ascending order by id.
Related LeetCode Problems
Practice more problems similar to Merge Two 2D Arrays by Summing Values.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.