Toeplitz Matrix

MATRIX

Problem

Given an m x n matrix, determine if it is Toeplitz.

A matrix is considered Toeplitz if every diagonal from the top-left to the bottom-right has identical elements. For each element in the matrix, check if it matches the element in the next row and column.

Return true if all diagonals contain identical elements; otherwise, return false.

Examples

/* [ [2,4,6], [8,2,4], [10,8,2] ] */ isToeplitzMatrix([[2,4,6],[8,2,4],[10,8,2]]) // true /* Why? The diagonals in this matrix are: "[10]", "[8, 8]", "[2, 2, 2]", "[4, 4]", "[6]". Each diagonal consists of the same elements, so the answer is true. */ isToeplitzMatrix([[5,10],[10,10]]) // false // The diagonal "[5, 10]" has different elements, so it's not Toeplitz.
Loading...
2
4
6
8
2
4
10
8
2