Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2570. Merge Two 2D Arrays by Summing Values #34

Open
PalmaAnd opened this issue Oct 10, 2023 · 0 comments
Open

2570. Merge Two 2D Arrays by Summing Values #34

PalmaAnd opened this issue Oct 10, 2023 · 0 comments
Assignees
Labels
easy Easy labeled Leetcode problem Leetcode Leetcode problem

Comments

@PalmaAnd
Copy link
Owner

Merge Two 2D Arrays by Summing Values

Link to the problem: https://leetcode.com/problems/merge-two-2d-arrays-by-summing-values/

Description:

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

nums1[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.
nums2[i] = [idi, vali] indicate that the number with the id idi has a value equal to vali.
Each array contains unique ids and is sorted in ascending order by id.

Merge the two arrays into one array that is sorted in ascending order by id, respecting the following conditions:

Only ids that appear in at least one of the two arrays should be included in the resulting array.
Each id should be included only once and its value should be the sum of the values of this id in the two arrays. If the id does not exist in one of the two arrays then its value in that array is considered to be 0.
Return the resulting array. The returned array must be sorted in ascending order by id.

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]]
Explanation: The resulting array contains the following:

  • id = 1, the value of this id is 2 + 4 = 6.
  • id = 2, the value of this id is 3.
  • id = 3, the value of this id is 2.
  • id = 4, the value of this id is 5 + 1 = 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]]
Explanation: There are no common ids, so we just include each id with its value in the resulting list.


@PalmaAnd PalmaAnd added easy Easy labeled Leetcode problem Leetcode Leetcode problem labels Oct 10, 2023
@PalmaAnd PalmaAnd self-assigned this Oct 10, 2023
@PalmaAnd PalmaAnd added this to the Arrays & Hashing milestone Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy Easy labeled Leetcode problem Leetcode Leetcode problem
Projects
None yet
Development

No branches or pull requests

1 participant