Spiral Matrix Problem

Spiral Matrix Problem — ExecCode Medium DSA Practice

Solve the Spiral Matrix problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given an m×n matrix, return all elements of the matrix in spiral order. For Spiral Matrix, focus on the exact input variables, return only the requested value, and preserve the required time complexity for the intended pattern.

Examples

Input matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; Output [1, 2, 3, 6, 9, 8, 7, 4, 5]

Constraints

1 ≤ m, n ≤ 10 -100 ≤ matrix[i][j] ≤ 100

Practice Spiral Matrix free on ExecCode. Browse DSA problems, topic map, and placement guides.