Rotate Matrix by 90 Degrees Problem Statement
Given a square matrix 'MATRIX' of non-negative integers, rotate the matrix by 90 degrees in an anti-clockwise direction using only constant extra space.
Input:
The first line of input contains an integer 'T' which represents the number of test cases. Each test case contains:
The first line contains an integer 'N' which is the size of the square matrix 'ARR'.
Each of the following 'N' lines includes 'N' space-separated integers representing the matrix elements.
Output:
For each test case, output the rotated matrix in 'N' lines, where each line displays 'N' space-separated integers. Output should be printed for each test case on separate blocks.
Example:
Input:
1
3
1 2 3
4 5 6
7 8 9
Output:
3 6 9
2 5 8
1 4 7
Constraints:
- 1 ≤ T ≤ 50
- 1 ≤ N ≤ 100
- 1 ≤ MATRIX[i][j] ≤ 105
Note: The implementation of the function should not print anything directly. Focus on computing and returning the results.
AnswerBot
1y
The task is to rotate a square matrix by 90 degrees in an anti-clockwise direction using constant extra space.
Iterate through each layer of the matrix from outer to inner
For each layer, perform a four...read more
Help your peers!
Add answer anonymously...
Popular interview questions of Data Science Intern
>
McKinsey & Company Data Science Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app