Tap here to switch tabs
Problem
Submissions

Problem: Merge Two 2D Arrays by Summing Values

med
30 min
Try to solve the Merge Two 2D Arrays by Summing Values problem.

Statement

You are given two 2D integer arrays nums1 and nums2.

Each array contains pairs of the form [id_i, val_i], indicating an identification number id_i and its associated value val_i. Both arrays are sorted in strictly ascending order by their identification numbers and contain unique identification numbers.

Merge the two arrays into a single 2D array sorted in strictly ascending order by id such that:

  • Each unique id appears only once in the result.

  • If an id is present in only one array, it retains its original value.

  • If an id is present in both arrays, its value becomes the sum of the values from both arrays.

Return the merged 2D array.

Constraints:

  • 1≤1 \leq nums1.length, nums2.length ≤200\leq 200

  • nums1[i].length == nums2[j].length =2= 2

  • 1≤1 \leq id_i, val_i ≤1000\leq 1000

  • Both arrays contain unique id values.

  • Both arrays are in strictly ascending order by id.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Merge Two 2D Arrays by Summing Values

med
30 min
Try to solve the Merge Two 2D Arrays by Summing Values problem.

Statement

You are given two 2D integer arrays nums1 and nums2.

Each array contains pairs of the form [id_i, val_i], indicating an identification number id_i and its associated value val_i. Both arrays are sorted in strictly ascending order by their identification numbers and contain unique identification numbers.

Merge the two arrays into a single 2D array sorted in strictly ascending order by id such that:

  • Each unique id appears only once in the result.

  • If an id is present in only one array, it retains its original value.

  • If an id is present in both arrays, its value becomes the sum of the values from both arrays.

Return the merged 2D array.

Constraints:

  • 1≤1 \leq nums1.length, nums2.length ≤200\leq 200

  • nums1[i].length == nums2[j].length =2= 2

  • 1≤1 \leq id_i, val_i ≤1000\leq 1000

  • Both arrays contain unique id values.

  • Both arrays are in strictly ascending order by id.