Border walk
Inputs
cells is a grid: a list of 1 to 5 rows, each with the same number (1 to 5) of whole numbers from -9 to 9.
Your tasks
- Create a number
totalthat starts at 0. - Use nested loops over every cell. Add a cell to
totalwhen it is on the edge: the first or last row, or the first or last column. - Complete
borderTotalso it returnstotal. Return it, do not print it.
Example
With cells = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], borderTotal returns 40.
Rules
- Cells in the middle are skipped.
- In a grid with one row or one column, every cell is on the edge.
Test data
TEST DATA 1: cells is [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
TEST DATA 2: cells is [[5]]
Practice focus
Two-dimensional data is a loop over rows with a loop over columns inside. Grids lead straight to flood fill, islands, dynamic programming tables and path problems.