Given a matrix of size N*M, and a number K. We have to rotate the matrix K times to the right side.
Input : N = 3, M = 3, K = 2 12 23 34 45 56 67 78 89 91 Output : 23 34 12 56 67 45 89 91 78 Input : N = 2, M = 2, K = 2 1 2 3 4 Output : 1 2 3 4
A simple yet effective approach is to consider each row of the matrix as an array and perform an array rotation. Which can be done by copying the elements from K to end of array to starting of array using temporary array. And then the remaining elements from start to K-1 to end of the arryay.
Lets take an example:
23 34 12 56 67 45 89 91 78
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Rotate a Matrix by 180 degree
- Rotate Matrix Elements
- Rotate a matrix by 90 degree without using any extra space | Set 2
- Inplace rotate square matrix by 90 degrees | Set 1
- Rotate each ring of matrix anticlockwise by K elements
- Rotate a matrix by 90 degree in clockwise direction without using any extra space
- Rotate bits of a number
- Rotate a Linked List
- Program to cyclically rotate an array by one
- Python | Ways to rotate a list
- Rotate Doubly linked list by N nodes
- Rotate Linked List block wise
- Minimum number of steps to convert a given matrix into Diagonally Dominant Matrix
- Minimum number of steps to convert a given matrix into Upper Hessenberg matrix
- Minimum steps required to convert the matrix into lower hessenberg matrix
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Circular Matrix (Construct a matrix with numbers 1 to m*n in spiral way)
- Check if a given matrix can be converted to another given matrix by row and column exchanges
- Program to check diagonal matrix and scalar matrix
- Check if it is possible to make the given matrix increasing matrix or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.