Loading
Loading
A scrolling LED panel shows numbers in a rectangular grid. In its screensaver mode a cursor starts in the top-left corner and reads every value once, travelling clockwise around the outside edge and then spiralling inward ring by ring.
Given the panel as panel, return the values in the order the cursor reads them.
panel = [[1,2,3,4],[5,6,7,8],[9,10,11,12]]1 2 3 4top row, left to right8 12right column, downward11 10 9bottom row, right to left5left column, upward6 7the inner ring is a single row[1,2,3,4,8,12,11,10,9,5,6,7]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
| 0 | 1 | 2 | 3 |
|---|---|---|---|
| 1 | 4 | 5 | 6 |
| 2 | 7 | 8 | 9 |
Example 2
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(rows × cols) time · O(1) extra space
Input. Run your code to watch it work on this input, one line at a time.
| 0 | 1 | 2 | 3 |
|---|---|---|---|
| 1 | 4 | 5 | 6 |
| 2 | 7 | 8 | 9 |
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
| 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 1 | 5 | 6 | 7 | 8 |
| 2 | 9 | 10 | 11 | 12 |
Example 3
| 0 | 4 |
|---|---|
| 1 | 8 |
| 2 | 15 |