FunctionRacerProblemsRace

Ring Walk

EasyGridsPython, JavaScript, TypeScript, Java, C++

Return the cells on the outer edge of grid in clockwise order, starting at the top-left cell: along the top row to the right, down the last column, along the bottom row to the left, and up the first column back towards the start. Every edge cell appears exactly once, so a cell is never listed twice even when two of these sides overlap. For a grid with a single row or a single column this is simply its cells in reading order.

Example 1

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

Top row 1, 2, 3; then down to 6 and 9; bottom row back to 8 and 7; then up to 4. The centre 5 is not on the edge.

Example 2

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

Two rows: the top row left to right, then the bottom row right to left.

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