Skip to main content

Practice · 5 of 5

Spiral fill

CHALLENGE
Difficulty: advanced+25 XP

Fill a rows x cols grid counting from 1 in **spiral order**: top row left→right, right column top→bottom, bottom row right→left, left column bottom→top, then shrink inward. Implement fill(int rows, int cols) returning the grid. Example: 3×4 → {{1,2,3,4},{10,11,12,5},{9,8,7,6}}.

Back to lesson: Practice: Grid lab: axes, neighborhoods, walls