Code RoomSpiral matrix generation
MediumPrep Room Coding #765

Spiral matrix generation

CodingAlgorithms & data structuresMid–Senior~25 min

Given a positive integer n, generate an n x n matrix filled with the integers 1 to n*n in clockwise spiral order starting from the top-left corner. Return the matrix. 1 <= n <= 20.

Implement
spiral_generate(n: int) → list[list[int]]
Examples
in[3]out[[1,2,3],[8,9,4],[7,6,5]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[3][[1,2,3],[8,9,4],[7,6,5]]not run yetsample