All problems
0596EasyArrayMatrix

Banded Woven Panel

Tracked in this browser only
Write code

Trains the technique from

LeetCode 766Toeplitz Matrix

This 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.

Examples

Example 1

Input
matrix = [[3, 7, 1], [4, 3, 7], [9, 4, 3]]
Output
true

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

Input
matrix = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
Output
false

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

Input
matrix = [[99, 98], [0, 99]]
Output
true

One band holds 99 and 99, and the remaining two bands hold a single square each, so every band is uniform.

Constraints

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 20
  • 0 <= matrix[i][j] <= 99

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def is_toeplitz_matrix(matrix: list[list[int]]) -> bool:
Java
public boolean isToeplitzMatrix(int[][] matrix)
September 7
Apply