Free written solution

Spiral Matrix III (LeetCode 885): Solution and Explanation

Start on a given cell of a rows x cols grid facing east and walk a clockwise spiral that keeps growing, even outside the grid. Return the coordinates of every grid cell in the order the walk first reaches it.

Read the intuition, approach, code and complexity →