leetle

Daily challenge for 2025-09-16

259. Spiral Matrix II

Given a positive integer n, generate an n x n matrix filled with elements from 1 to n² in spiral order.

Example:
Input: n = 3
Output: [[1,2,3],[8,9,4],[7,6,5]]

The matrix should be filled in spiral order: right → down → left → up → right...

Run this challenge interactively in Python or JavaScript when the app loads.