grid with m rows and n columns (rows are numbered from zero) and an integer steps.
In one step every row is rotated cyclically by one position at the same time:
- even-numbered rows (0, 2, 4, …) rotate left: the first element moves to the end;
- odd-numbered rows (1, 3, 5, …) rotate right: the last element moves to the front.
Perform steps such steps. Return True if the resulting matrix is identical to the original one, and False otherwise.grid=[[1, 2, 1, 2], [3, 4, 3, 4]], steps=2 → True
Each row repeats with period 2, so after two shifts in either direction it looks exactly as before.
grid=[[1, 2, 3], [4, 5, 6]], steps=1 → False
After one step the first row becomes [2, 3, 1] and the second becomes [6, 4, 5], so the grid has changed.
grid=[[5, 6, 7], [8, 9, 1], [2, 3, 4]], steps=6 → True
grid[i][j] ≤ 25steps ≤ 50grid=[[1, 2, 1, 2], [3, 4, 3, 4]], steps=2
True
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.