Given an m x n grid and an integer k, shift the grid k times and return it. In one shift, grid[i][j] moves to grid[i][j + 1], grid[i][n - 1] moves to grid[i + 1][0], and grid[m - 1][n - 1] moves to grid[0][0].
Given an m x n grid and an integer k, shift the grid k times and return it. In one shift, grid[i][j] moves to grid[i][j + 1], grid[i][n - 1] moves to grid[i + 1][0], and grid[m - 1][n - 1] moves to grid[0][0].
Example 1:
Input: {"grid":[[1,2,3],[4,5,6],[7,8,9]],"k":1}
Output: [[9,1,2],[3,4,5],[6,7,8]]
Constraints:
m=grid.length
n=grid[i].length
1≤m≤50
1≤n≤50
−1000≤grid[i][j]≤1000
0≤k≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"grid":[[1,2,3],[4,5,6],[7,8,9]],"k":1}
Shifting 1 time moves every value 1 step forward in reading order, wrapping from the last cell to the first.