Toeplitz Matrix
Read at your own pace. Code execution, quizzes, progress tracking, and the AI tutor are available in the interactive view with JavaScript enabled.
Question
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false.

For example, consider the matrices above. The first matrix has all its diagonals filled with the same elements, whereas the second matrix has only two diagonals with the same elements. Having even a single diagonal with different elements would not make the matrix, a Toeplitz matrix.
Constraints
m == matrix.lengthn == matrix[i].length1 <= m, n <= 200 <= matrix[i][j] <= 99
CONTINUE WITH ALGODAILY PREMIUM
Keep going with the complete tutorial.
Unlock the remaining explanations and exercises, alongside the full learning library.
Explore Premium →