Ring Walk
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
1 <= rows, cols <= 10-100 <= grid[r][c] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Row and Column SwitchesEasy
- Same Letter RegionEasy
- Stones SettleEasy
- Turns to MatchEasy
- Turtle CommandsEasy
- Up and to the RightEasy
- Wireworld StepEasy
- Crush and FallMedium