FunctionRacerProblemsRace

Frame Total

BeginnerGridsPython, JavaScript, TypeScript, Java, C++

A cell of grid is on the frame when it lies in the first row, the last row, the first column or the last column. Return the sum of all frame cells, counting each cell once even if it is in a corner. When grid has only one row or only one column, every cell is on the frame.

Example 1

grid [[1,2,3],[4,5,6],[7,8,9]]
returns 40

Only the centre cell 5 is not on the frame, so the answer is 45 - 5 = 40.

Example 2

grid [[1,2,3,4],[5,6,7,8]]
returns 36

With two rows every cell is in the first or the last row, so all eight cells count.

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