← All problems

Spiral Matrix

MediumMatrix

Given an m × n matrix, return all its elements in spiral order (clockwise, starting top-left).

Examples

Input: [[1,2,3],[4,5,6],[7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]

Hints

Solution

Language:
Loading editor…
Output0 lines
Run your code to see output here.
Click Run all tests to check your solution against 3 test cases.