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.
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 it...read more
Top Smart Energy Water Software Developer interview questions & answers
Popular interview questions of Software Developer
Reviews
Interviews
Salaries
Users/Month