Circular Matrix Spiral
Given an n x n matrix filled with integers, write a function to return a list of elements in the matrix in a circular, clockwise spiral order starting from the top-left corner.
[ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ]
Explanation. Starting from top-left, we first move right across the top, then downwards along the right column, then left across the bottom row and finally upwards along the left column.
[ [ 1 ] ]
Explanation. The matrix has only one element, so the spiral is simply that single element.
[ [ 1, 2 ], [ 4, 3 ] ]
Explanation. The spiral order begins at the top-left, moves right, then downward, and finally left.
Follow-up: How would your solution change if the spiral needs to start from a different corner of the matrix?
- `n` is the size of the matrix (n x n)\n- The matrix will be filled with integers.\n- `1 <= n <= 100`
- Views
- 3