Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 611 Bytes

README.md

File metadata and controls

29 lines (20 loc) · 611 Bytes

question of the day: https://leetcode.com/problems/spiral-matrix-ii/#/description

Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.

For example, given n=3, return the following matrix:

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

Ideas

Brute force: create a matrix with placeholder values, copy over my code from day 11, and modify that spiral motion code to replace values with ascending values of 1..n<sup>2</sup> .

That'd be O(n^2) space and runtime.

Code

Python

Follow up