Tap here to switch tabs
Problem
Submissions

Problem: Spiral Matrix II

Spiral Matrix II gives you a positive integer n and asks you to return an n by n matrix containing every value from 1 through n squared in spiral order.

Statement

Given a positive integer n, create an n×nn \times n matrix where the elements are sequential integers from 11 to n2n^2, arranged in a spiral pattern.

Constraints:

  • 1 ≤\leq n ≤\leq2020

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Spiral Matrix II

Spiral Matrix II gives you a positive integer n and asks you to return an n by n matrix containing every value from 1 through n squared in spiral order.

Statement

Given a positive integer n, create an n×nn \times n matrix where the elements are sequential integers from 11 to n2n^2, arranged in a spiral pattern.

Constraints:

  • 1 ≤\leq n ≤\leq2020