Rotate Matrix to the Right
You are provided with a matrix MAT
of size 'N' * 'M', where 'N' is the number of rows and 'M' is the number of columns. Your task is to rotate the matrix to the right 'K' times, where 'K' is a positive integer.
Note:
Right rotation on a matrix involves shifting each column to the right (with the last column moving to the first column). Performing this operation 'K' times implies executing the right rotation 'K' times.
Example:
Input:
For 'K' = 1
MAT =
1 2 3
4 5 6
7 8 9
Output:
3 1 2
6 4 5
9 7 8
Input:
The first line contains an integer 'T', the number of test cases.
Each test case consists of:
- A line with three integers 'N', 'M', and 'K', separated by spaces.
- Followed by 'N' lines each containing 'M' integers, representing a matrix row.
Output:
For each test case, return the elements of the matrix row-wise after rotation as a single line.
Constraints:
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 200
- 1 ≤ M ≤ 200
- 0 ≤ K ≤ 109
- 1 ≤ MAT[i][j] ≤ 105
Where 'MAT[i][j]' denotes the element in the 'i'th row and 'j'th column of the matrix. Time limit: 1 sec.
Be the first one to answer
Add answer anonymously...
Top Smart Energy Water Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Smart Energy Water Software Developer 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