ALG-M009MediumMatrix
Clockwise Matrix Walk
Return the entries of a rectangular integer matrix in clockwise spiral order, starting at its top-left corner and moving right first.
Contract
input matrix: integer[][]
return integer[]
Constraints
- • Rows all have equal length
- • 0 <= rows, columns <= 100
Examples
Example 1
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
→ [1, 2, 3, 6, 9, 8, 7, 4, 5]
Example 2
matrix = [[1, 2, 3, 4]]
→ [1, 2, 3, 4]
5 judge tests (2 shown above). Target complexity: O(rows*cols).