The problem
A timetable board is a grid: a list of rows, all the same length. Return a list of its values in spiral order, going clockwise from the top-left corner: along the top row, down the right column, back along the bottom row, up the left column, and then the same for the next ring in. Do not change grid.
spiral([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]) # [1, 2, 3, 6, 9, 8, 7, 4, 5]
spiral([[1, 2, 3, 4]]) # [1, 2, 3, 4]
spiral([]) # []
Limits
- Up to 500 rows and 500 columns. The grid need not be square.
Builds on ARRS-5 Matrices and 2-D traversal.
Continue on a laptop
Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.
Need a hint?0 of 3 opened
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
9 tests, not run yet
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | 3 by 3 | Not run | |
| 2 | 3 by 4 | Not run | |
| 3 | 4 by 3 | Not run | |
| 4 | One row | Not run | |
| 5 | One column | Not run | |
| 6 | One cell | Not run | |
| 7 | Empty grid | Not run | |
| 8 | Grid not changed | Not run | |
| 9 | 500 by 400 | Not run |