Spiral Order
Hard 70 XPMatrix
Commonly asked at Zoho, Microsoft, Amazon, Google
Read r and c, then an r × c matrix. Print its elements in clockwise spiral order (starting top-left, going right), on one line separated by spaces.
- Input
- Line 1: r c. Next r lines: c integers each.
- Output
- All elements in spiral order.
Sample 1
Input
3 3 1 2 3 4 5 6 7 8 9
Output
1 2 3 6 9 8 7 4 5
Read input with input() (no prompt message) and print only the answer. Run tries the Input box; Submit checks all test cases.
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.The solution unlocks after 3 submissions.