55. Spiral Matrix II

MediumMatrix

Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n^2` in spiral order.

Examples

Input: 3

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

Explanation: Values 1..9 wound inward in spiral order.

Constraints

  • 1 <= n <= 20
Loading...

Run checks all cases above. Submit evaluates all test cases.