Spiral Matrix 2 - Generate

Problem Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Examples Example 1: Input: n = 3 Output: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ] Example 2: Input: n = 4 Output: [ [1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7] ] ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy