You are given a 2D matrix with m rows and n columns, along with an integer k.
Each shift operation moves elements forward in row-major order:
Every element at position (i, j) moves to (i, j+1).
If it is currently at the end of the row, it moves to the start of the next row.
The last element of the grid wraps around to position (0, 0).
You must perform exactly k such shifts and return the final configuration of the grid.
Input: grid = [[5,6],[7,8]], k = 2
Output: [[7,8],[5,6]]
Explanation:
After two shifts, elements rotate twice in order.
Input: grid = [[1,4,7],[2,5,8],[3,6,9]], k = 3
Output: [[7,1,4],[8,2,5],[9,3,6]]
Explanation:
Matrix shifts three positions forward in sequence.
Input: grid = [[10]], k = 5
Output: [[10]]
Explanation:
A single-cell grid always remains unchanged.
Accepted:
Submission: