Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Toeplitz Matrix

XPChallenge Points: 10
levelLevel: Easy

You are given an m × n 2D matrix.
Your task is to determine whether the matrix is a Toeplitz matrix.

A matrix is called Toeplitz if every diagonal from top-left to bottom-right contains the same value.
In other words, for every valid position (i, j), the following must hold:

matrix[i][j] == matrix[i-1][j-1]

If all diagonals satisfy this, return true.
Otherwise, return false.

Example 1:

Input: matrix = [[1,2,3,4], [5,1,2,3], [9,5,1,2]]

Output: true

Explanation:

Each diagonal has identical values: [9] [5,5] [1,1,1] [2,2,2] [3,3] [4] So the matrix is Toeplitz.

Example 2:

Input: matrix = [[1,2],[2,2]]

Output: false

Explanation:

The diagonal [1,2] contains different values → not Toeplitz.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result