Trains the technique from
LeetCode 1260Shift 2D GridThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A tile board is a grid of m rows by n columns of numbers, given as grid.
One roll moves every tile one place along, reading the board row by row from the top left: a tile moves to the next column of its own row, a tile in the last column moves to the first column of the row below, and the tile in the bottom right corner moves to the top left.
Return the board after k rolls.
Example 1
Every tile moves one place along the row-by-row reading, and the 1 in the bottom right corner wraps round to the top left.
Example 2
The board holds nine tiles, so nine rolls bring every tile back to where it started.
Example 3
The board has a single column, so the 6 moves down into the second row and the 8 wraps round to the first.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def roll_board(grid: list[list[int]], k: int) -> list[list[int]]:public List<List<Integer>> rollBoard(int[][] grid, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.