Rotate Matrix K times

Moderate
0/80
5 upvotes
Asked in companies
Josh Technology GroupUHGZoho Corporation

Problem statement

Given a matrix, clockwise rotate elements in it K times. Rotating the matrix by 90 degrees clockwise will be counted as 1.

See the sample input.

Detailed explanation ( Input/output format, Notes, Images )
Input format :
Line 1 : Number of rows M and cols N in the matrix
Line 2 to M + 1 : MXN elements of the matrix
Line M + 2 : Integer K
Output Format :
 Just rotate the given matrix, no need to print it
Constraints :
 1 <= M <= 10^5
 1 <= N <= 10^5
 1 <= K <= 10^5
Sample Input :
3 4
2 3 8 8 
8 4 8 1 
7 6 0 5 
1
Sample Output :
8 2 3 8 
7 4 8 8 
6 0 5 1 
Approaches (1)
Time Complexity
Space Complexity
Code Solution
(100% EXP penalty)
Rotate Matrix K times
Full screen
Console