Loading...
Loading...
Loading...
Read a table of r rows and c columns. Print its values in spiral order: along the top row left to right, down the right column, along the bottom row right to left, up the left column, then repeat on the inside. Print all values on one line.
Example
Input
3 3 1 2 3 4 5 6 7 8 9
Output
1 2 3 6 9 8 7 4 5
Around the edge, then the middle value 5.
Try the problem first. Open one hint at a time.
Keep four limits: top, bottom, left, right. After each side is walked, move that limit one step inward.
After the top row and the right column, check that rows and columns are left before walking the bottom row and the left column.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor