Deviopath › JavaScript

Spiral Matrix

Hard · Arrays

Write a function spiralOrder that returns all values of a 2D array (matrix) in spiral order: start at the top-left, go right along the top row, then down the right column, then left along the bottom row, then up, and keep going inwards.

The matrix can be rectangular. For an empty matrix return [].

Next: Longest Substring Without Repeats