Generate M by N Spiral Matrix

Problem: Generate an m × n Spiral Matrix

Given two positive integers m and n, return an m x n 2D matrix filled with numbers from 1 to m * n in clockwise spiral order.

The spiral starts ...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: