FunctionRacerProblemsRace

Cross Total

BeginnerGridsPython, JavaScript, TypeScript, Java, C++

grid is a rectangle of integers given as a list of rows (the outer list holds the rows). The cross through the cell in row row and column col (both counted from 0) is made of every cell in that row together with every cell in that column. Return the sum of the cells in the cross, counting the cell where the row and the column meet only once. Do not change grid.

Example 1

grid [[1,2,3],[4,5,6],[7,8,9]]
row 1
col 1
returns 25

Row 1 adds up to 4 + 5 + 6 = 15 and column 1 adds up to 2 + 5 + 8 = 15. The centre 5 belongs to both, so the cross totals 15 + 15 - 5 = 25.

Example 2

grid [[2,-1,0,3],[1,1,1,1]]
row 0
col 3
returns 5

Row 0 adds up to 2 - 1 + 0 + 3 = 4, and the only other cell of column 3 adds 1, for a total of 5.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Grids problems