Spiral Matrix II
Given a positive integer n, generate an n x n matrix filled with elements from 1 to n² in spiral order.

30:00

Spiral Matrix II
medium
Topics
Companies

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

Example 1:
Input: 3
Output: [[1,2,3],[8,9,4],[7,6,5]]
Constraints:
  • 1n201 \leq n \leq 20

Input
arr =3

Generate 3×3 spiral matrix

Next Number
1
Direction
right
Filled
0/9
3 × 3 Matrix
→ Right
↓ Down
← Left
↑ Up
Variables
No variables to display
DepthFunction Call
Stack empty
0/14