Algorithm · ByteDance · Medium
For a given integer n, construct an n x n grid containing every integer from 1 through n^2. Place the values by beginning in the upper-left cell and moving clockwise in a spiral. Input and Output Example: The numbers are written around the outside first, then continue clockwise toward the center. Data Scale: 1 <= n <= 20 Example Input: 1 Output: With a 1 x 1 matrix, the only required value is 1.
Checking your access…