Problems > Toeplitz Matrix

Toeplitz Matrix

Difficulty: 1100 2000 ms 128 MB

implementation

Is the matrix Toeplitz — constant along every top-left-to-bottom-right diagonal?

Input: the first line has N and M; the next N lines each have M integers.

Output: YES or NO.

Constraints:

  • 1 ≤ N, M ≤ 100

Sample Tests

Input 1
3 4
1 2 3 4
5 1 2 3
9 5 1 2
Output 1
YES
Input 2
2 2
1 2
2 2
Output 2
NO

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.