A grid is Toeplitz if every diagonal running from top-left to bottom-right contains the same value along its whole length. Given an m x n grid matrix, return True if it is Toeplitz and False otherwise.
Examples
Input: matrix = [[7, 0, 4], [2, 7, 0], [5, 2, 7], [8, 5, 2]]
Output: True
Explanation: the diagonals are [8], [5, 5], [2, 2, 2], [7, 7, 7], [0, 0], [4].
Input: matrix = [[3, 1, 2], [9, 3, 1], [4, 9, 1]]
Output: False
Explanation: the main diagonal [3, 3, 1] is not constant.
Constraints
1 <= m, n <= 500- Target: O(m * n) time, O(1) extra space.
Goals
- Compare each cell with its upper-left neighbour
- Skip the first row and column, which have no such neighbour
- Stop early on the first mismatch