As reported: Adobe Computer Scientist 1 interview (Noida, 2025), round 1: Spiral Matrix II — the interviewer showed the full spiral and asked for it to be printed; generating the matrix first and then printing it was accepted.
This is LeetCode 59 — Spiral Matrix II.
Given n, fill an n × n matrix with the numbers 1 to n² in clockwise spiral order, starting at the top-left corner and moving right, and return it (printing it row by row is then a simple loop).
Example 1
n = 3
Output:
1 2 3
8 9 4
7 6 5
Example 2
n = 1
Output: [[1]]
Constraints: 1 ≤ n ≤ 20.
Code runner format: one JSON value per line: n. Implement generateMatrix(n); the harness prints the matrix as a JSON array of rows, e.g. [[1,2,3],[8,9,4],[7,6,5]].