Math with Lego Blocks
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.
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.
1Example 1
2Example 2

Constraints
Limits and guarantees your solution can rely on.
- 1 ≤ n, m ≤ 10^5
- 0 ≤ rowA[i], rowB[j] ≤ 10^4