Imagine you're looking at a Toeplitz Matrix - a special type of matrix where every diagonal from top-left to bottom-right contains identical elements! This creates a beautiful pattern where elements "cascade" down and to the right.
Given an m x n matrix, your task is to determine if it follows this special property. Return true if the matrix is Toeplitz, otherwise return false.
What makes a matrix Toeplitz?
- Every diagonal from top-left to bottom-right has the same elements
- For any element at position
(i, j), it should equal the element at(i+1, j+1) - This pattern continues throughout the entire matrix
Example: In matrix [[1,2,3,4],[5,1,2,3],[9,5,1,2]], the diagonals are [1,1,1], [2,2,2], [3,3], [4], [5,5], [9] - all elements in each diagonal are identical!
Input & Output
Visualization
Time & Space Complexity
We visit each element once, except the last row and column
We only use a constant amount of extra space
Constraints
- m == matrix.length
- n == matrix[i].length
- 1 ≤ m, n ≤ 20
- 0 ≤ matrix[i][j] ≤ 99