You are given a 2D array matrix of size m x n.
Return all the elements of the matrix in a spiral (clockwise) order, starting from the top-left corner and moving inward layer by layer.
Input: matrix = [[1,2,3], [4,5,6], [7,8,9]]
Output: [1,2,3,6,9,8,7,4,5]
Input: matrix = [[1,2,3,4], [5,6,7,8], [9,10,11,12], [13,14,15,16]]
Output: [1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10]
Accepted:
Submission: