Skip to main content
mediumBlind 75

Spiral Matrix

Given an m x n matrix, return all elements in spiral order Traverse: right → down → left → up → repeat inward Example: [[1,2,3],[4,5,6],[7,8,9]] => [1,2,3,6,9,8,7,4,5]

Spiral Matrix turns a simple directional walk into careful boundary bookkeeping: sweep right, down, left, and up, tightening the four edges after each pass. The edge cases worth walking by hand are rectangular matrices where the final sweep is a single row or column.

Arrays & HashingSimulation

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Typing with Coco is free when you sign in, up to a daily limit. Talking with her out loud comes with the $79 pack. Anyone can open the editor and run their code.

1Spiral Matrix Traversalmedium
Based onLeetCode