
Rotate Matrix Right K Times
You are given a matrix MAT
of size 'N' * 'M', where 'N' is the number of rows and 'M' is the number of columns, along with a positive integer 'K'. Your task is to rotate the matrix to the right 'K' times.
Explanation
Right rotation on a matrix involves shifting each column to the right (where the last column shifts to the first column). This is done 'K' times as specified.
Input:
The first line of input contains an integer 'T' representing the number of test cases.
Each test case contains:
First line: Three integers 'N', 'M', and 'K' denoting the rows, columns, and the number of rotations respectively.
Next 'N' lines: Each contains 'M' space-separated integers representing the matrix rows.
Output:
For each test case, return the matrix elements row-wise after performing the right rotations as a single line.
Example:
Input:
1
3 3 1
1 2 3
4 5 6
7 8 9
Output:
3 1 2 6 4 5 9 7 8
Constraints:
1 <= T <= 10
1 <= N <= 200
1 <= M <= 200
0 <= K <= 10^9
1 <= MAT[i][j] <= 10^5
Note:
You are not required to print the output as it has been handled. Just implement the function to return the result.

AnswerBot
11d

Rotate a matrix to the right 'K' times by shifting each column to the right 'K' times.
Iterate 'K' times to perform right rotation on the matrix
Shift each column to the right by one position in each ro...read more

Help your peers!
Add answer anonymously...
Top Oyo Rooms Software Developer interview questions & answers
Popular interview questions of Software Developer
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