ARRS-P4

The spiral timetable

Practice 4 of 5Arrays and strings9 tests

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

  1. Hint 1Nudge
  2. Hint 2Approach Open hint 1 first
  3. Hint 3Pseudocode Open hint 2 first
  4. Worked solutionlast resort Opens after all 3 hints
Python waits for a wider screensolution.py

Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.

9 tests, not run yet
Test results
#TestResultReads · time
13 by 3Not run
23 by 4Not run
34 by 3Not run
4One rowNot run
5One columnNot run
6One cellNot run
7Empty gridNot run
8Grid not changedNot run
9500 by 400Not run