Math with Lego Blocks
Updated
Problem 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 = 10Replace the zero in rowA with 1 so that rowA = [2, 5, 1, 1, 1]. Replace the zeroes in rowB with 3 and 4 so that rowB = [2, 1, 3, 4].
Example 2
rowA = [1, 0, 2]rowB = [1, 3, 0, 0]return = 6
After replcing the 0s in the rows: rowA = [1, 3, 2] rowB = [1, 3, 1, 1] The sum of elements in rowA is 1 + 3 + 2 = 6 and the sum of elements in rowB is 1 + 3 + 1 + 1 = 6. This is the min possible equal sum that can be achieved. Hence, the answer is 6.
Constraints
- 1 ≤ n, m ≤ 10^5
- 0 ≤ rowA[i], rowB[j] ≤ 10^4
More Citadel interview questions
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Possible MEX Values After One Optional IncrementOA · Seen Oct 2026
- Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
- Top Ten Trades by Notional ValuePHONE SCREEN · Seen Sep 2026
- Busy IntersectionOA · Seen Sep 2026
- Shortest Path in an Unweighted GraphOA · Seen Sep 2026
Similar questions at other companies
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Minimum Values with Even Powers of TwoVisa · OAVisa interview questions
- Minimize Adjacent Squared-Difference Cost with One InsertionMicrosoft · OAMicrosoft interview questions
- Minimum Halvings for Alternating ParityIBM · OAIBM interview questions
- Resource AllocationMaven Securities · OAMaven Securities interview questions
- Rock JumpingIMC Trading · OAIMC Trading interview questions
- Minimum Total Batch ExpenseAmazon · OA
- Minimum Increments for Stepwise TowersZipRecruiter · OAZipRecruiter interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences