DAYS
HOUR
MINS
SEC
Error
Given a matrix as 2D array. Return the matrix in reverse spiral form.​
Example 1:
Input: R = 3, C = 3
a = {{9, 8, 7},
{6, 5, 4},
{3, 2, 1}}
Output: {5 6 3 2 1 4 7 8 9}
Explanation: Spiral form of the matrix
is 9->8->7->4->1->2->3->6->5 and then
reverse.
Example 2:
Input: R = 4, C = 4
a = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12},
{13, 14, 15, 16}}
Output: {10 11 7 6 5 9 13 14 15 16 12 8 4 3 2 1}
Explanation: Spiral form of the matrix
is 1->2->3->4->8->12->16->15->14->13->9
->5->6->7->11->10 and then reverse.
Your Task:
You dont need to read input or print anything. Complete the function reverseSpiral() which takes R, C and a as input parameters and returns the matrix in reverse spiral form.
Expected Time Complexity: O(R*C)
Expected Auxiliary Space: O(R*C)
Constraints:
1 <= R,C <=100
1 <= a[R][C] <=100
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Yes