Given a positive integer `n`, generate an `n x n` `matrix` filled with elements from `1` to `n^2` in spiral order.
Example 1
Input: n = 3
Output: [[1,2,3],[8,9,4],[7,6,5]]
Explanation: Fill 1, 2, 3 across the top, 4, 5 down the right side, 6, 7 back along the bottom, 8 up the left side, and 9 in the centre.
Example 2
Input: n = 1
Output: [[1]]
Explanation: A single cell holds 1.
Example 3
Input: n = 2
Output: [[1,2],[4,3]]
Explanation: Fill 1, 2 across the top, 3 down to the bottom-right, and 4 back to the bottom-left.
Keep four shrinking boundaries — top, bottom, left, right. Fill the top row left-to-right, the right column top-to-bottom, the bottom row right-to-left, the left column bottom-to-top, then move the boundaries inward. A running counter supplies the values 1..n^2.
Run checks all cases above. Submit evaluates all test cases.