PIXELBANKv9.1.0
Menu

Given an m x n matrix, return all elements in spiral order.

Output space-separated.

Example:

Input:
1,2,3
4,5,6
7,8,9
Output:
1 2 3 6 9 8 7 4 5
Reasoning:
  • We start at the top row and move right, printing elements in order: 1, 2, 3
  • Then, we move down to the next row and print the last element of the current column: 6
  • Next, we move left along the bottom row, printing elements in reverse order: 9, 8, 7
  • Finally, we move up the first column, printing the remaining element: 4, 5, resulting in the spiral order: 1 2 3 6 9 8 7 4 5

Constraints:

  • 1 <= m, n <= 10
  • -100 <= matrix[i][j] <= 100
solution.py

Test Results

0/0
Run code to see test results.
Spiral Matrix - Medium | PixelBank