Math with Lego Blocks
Learn this problemProblem statement
To make learning more interactive and fun for students, a math teacher decides to teach a concept to students by using Lego blocks. There are 2 rows of legos, rowA (of length n) and rowB (of length m). Both rows hold legos with positive integer values printed on them. However, some values (possibly, none) are missing. The missing values are denoted by 0. Students need to incorporate the missing values. The task is to replace each 0 with a positive integer such that the sums of both arrays are equal. Return the minimum sum possible. If it is not possible to make the sums equal, return -1.
Function
findMinimumEqualSum(rowA: int[], rowB: int[]) → int
Complete the function findMinimumEqualSum in the editor.
findMinimumEqualSum has the following parameters:
- 1.
int rowA[n]: one row of integers - 2.
int rowB[m]: another row of integers
Returns
int: an integer, which, if positive, denotes the minimum equal sum, and if -1 indicates that it is not possible to obtain an equal sum.
Examples
Example 1
rowA = [2, 5, 0, 1, 1]rowB = [2, 1, 0, 0]return = 10Example 2
rowA = [1, 0, 2]rowB = [1, 3, 0, 0]return = 6
Constraints
- 1 ≤ n, m ≤ 10^5
- 0 ≤ rowA[i], rowB[j] ≤ 10^4
More Citadel problems
- Minimum Changes for a Periodic PalindromeOA · Seen Jul 2026
- Minimum Image Processing CostOA · Seen Jul 2026
- Minimum Path Sum to Target in Binary TreePHONE SCREEN · Seen Apr 2026
- Minimum Time to Process RequestsOA · Seen Mar 2026
- Process SchedulingOA · Seen Mar 2026
- Social Media SuggestionsSeen May 2025
- Best Sum Downward Tree PathSeen May 2025
- Price CheckSeen Feb 2025