Easy · Diagonal Invariant
Understand → Visualise → Practice.
Return whether every top-left to bottom-right diagonal contains one repeated value.
A matrix is Toeplitz exactly when every cell (r, c) with r, c ≥ 1 equals the cell at (r − 1, c − 1).
Those cells start a diagonal and have nothing to compare with.
Check matrix[r][c] == matrix[r − 1][c − 1] for every other cell.
Any mismatch means false.
O(rows × cols) time and O(1) space.
Collecting each diagonal into a list works but uses extra space you don't need.
Read the full guide first: Matrices and 2-D Arrays.
Guest mode lets you understand, visualise and run the sample tests. Create a free account to submit and save your solutions.