Toeplitz Matrix

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 it is Toeplitz. (Equivalently, check if each element equals the element up-left of it.)

Input Format

2D list of ints.

Output Format

Boolean.

Constraints

  • m,n ≤ 20; matrix values arbitrary.

Examples

Example 1:

Input:

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

Output:

true

Example 2:

Input:

matrix = [[1,2],[2,2]]

Output:

false

Example 3:

Input:

matrix = [[1]]

Output:

true
Loading...
Toeplitz Matrix - Matrix DSA Problem