Skip to content

Latest commit

 

History

History

25-06-2024

Go To Problem

Left Rotate Matrix K times

Medium
Accuracy: 41.89% Points: 4

You are given an integer k and matrix mat. Rotate the elements of the given matrix to the left k times and return the resulting matrix.

💡Example 1:

Input :
   k=1, mat=[[1,2,3],[4,5,6],[7,8,9]]
Output :
  2 3 1
  5 6 4
  8 9 7
Explanation: Rotate the matrix by one
1 2 3       2 3 1
4 5 6  =>  5 6 4
7 8 9       8 9 7

💡Example 2:

Input:
    k=2, mat=[[1,2,3],[4,5,6],[7,8,9]]
Output: 
    3 1 2
    6 4 5
    9 7 8
Explanation: After rotating the matrix looks like
1 2 3       2 3 1       3 1 2
4 5 6  =>  5 6 4  =>   6 4 5
7 8 9       8 9 7       9 7 8

Expected Time Complexity:

O(n*m)

Expected Space Complexity:

O(n*m)

Constraints:

1<= mat.size, mat[0].size, mat[i][j] <=1000

1<=k<=10000

Company Tag:

Topic Tags:

Codes: