43. Toeplitz Matrix

EasyArrayArray

Given an m x n matrix, return true if the matrix is Toeplitz. A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.

Input: A 2D integer array matrix of size m x n.

Output: true if Toeplitz, false otherwise.

Examples

Example 1
Input: [[1,2,3,4],[5,1,2,3],[9,5,1,2]]
Output: true
Explanation: Each top-left to bottom-right diagonal has all equal elements. Toeplitz.
Example 2
Input: [[1,2],[2,2]]
Output: false
Explanation: Diagonal starting at (0,0) has [1,2] — not all equal. Not Toeplitz.
Example 3
Input: [[1,1,1],[1,1,1],[1,1,1]]
Output: true
Explanation: All elements equal → all diagonals trivially equal. Toeplitz.

Constraints

Asked by

WiproMetaGoogle
Solve this problem in the editor →