Trains the technique from
LeetCode 766Toeplitz MatrixThis 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 loom produces a rectangular panel of coloured squares, handed to you as matrix, where matrix[i][j] is the colour code woven into row i, column j.
A band of the panel is traced by starting on some square and stepping repeatedly one row down and one column to the right, until the next step would leave the panel. Every square of the panel lies on exactly one band.
The panel is cleanly banded when all the squares of each band carry the same colour code. Return true when the panel is cleanly banded and false otherwise.
Example 1
The bands hold the colour codes 3, 3, 3 then 7, 7 then 1 then 4, 4 then 9, and every band carries a single code.
Example 2
The band starting at row 0, column 0 visits the codes 1, 2 and 3, which are not all equal, so the panel is not cleanly banded.
Example 3
One band holds 99 and 99, and the remaining two bands hold a single square each, so every band is uniform.
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 is_toeplitz_matrix(matrix: list[list[int]]) -> bool:public boolean isToeplitzMatrix(int[][] matrix)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.