grid and an integer goal. Pick exactly one number from every row of the matrix and add the picked numbers together.
Return the smallest possible value of |sum − goal|.grid=[[2, 9], [4, 1], [6, 3]], goal=12 → 0
Take 2, 4 and 6: the sum is 12, exactly the goal, so the gap is 0.
grid=[[5, 6], [7, 8]], goal=30 → 16
The largest sum is 6 + 8 = 14, which falls short of 30 by 16.
grid=[[10, 20, 30]], goal=24 → 4
grid[i][j] ≤ 70goal ≤ 800grid=[[2, 9], [4, 1], [6, 3]], goal=12
0
Run checks the first 3 tests in your browser. Submit checks all 90 tests on the server, hidden ones included.