Spiral Matrix

Medium
ArrayMatrixSimulationAmazonMicrosoft
Given an m x n matrix, print all of its elements in spiral order, starting at the top-left corner and moving clockwise. Input format: - First line: m n - Next m lines: n integers each Print the elements on one line, separated by spaces.

Constraints

1 <= m, n <= 1000
1 <= m * n <= 2 * 10^5
-10^9 <= matrix[i][j] <= 10^9

Sample tests

Sample 1

Sample 2

Sign in to submit