Trains the technique from
LeetCode 1914Cyclically Rotating a 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 mosaic is stored as mosaic, a rectangular table of colour codes with an even number of rows and an even number of columns.
The mosaic is made of nested rings. The outermost ring is every cell on the border of the table; the next ring is the border of what is left once that ring is taken away, and so on. Because both side lengths are even, every ring is a closed loop of cells.
Read a ring by starting at its top-left cell and going clockwise: across its top row from left to right, down its right column, back across its bottom row from right to left, then up its left column. One shift moves the code in each position of that reading into the position one place earlier, and the code in the first position moves to the last position.
Every ring is shifted shifts times, all rings at once and each within itself. Return the mosaic afterwards.
Example 1
The whole mosaic is one ring, read clockwise as 7, 9, 8, 6. After one shift each code sits one place earlier in that reading, so the reading becomes 9, 8, 6, 7.
Example 2
The outer ring reads 1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5 and the inner ring reads 6, 7, 11, 10. Each code moves two places earlier in its own reading.
Example 3
This mosaic is a single ring, read clockwise as 1, 2, 3, 4, 8, 7, 6, 5. After seven shifts that same reading is 5, 1, 2, 3, 4, 8, 7, 6.
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 spin_mosaic(mosaic: list[list[int]], shifts: int) -> list[list[int]]:public int[][] spinMosaic(int[][] mosaic, int shifts)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.