Loading content...
You are given an m x n grid of integers. Your task is to determine whether this grid exhibits diagonal uniformity — a structural property where every diagonal running from the upper-left toward the lower-right contains identical values throughout its entire length.
Specifically, a grid is considered diagonally consistent if and only if for every cell at position (row, col), the value at that cell equals the value at (row + 1, col + 1) whenever both positions are within the grid boundaries. In other words, as you traverse any diagonal stripe from top-left to bottom-right, all elements along that stripe must share the same value.
Return true if the given matrix satisfies this diagonal consistency property, and false otherwise.
matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]trueAnalyzing each diagonal from top-left to bottom-right: The diagonals are [9], [5,5], [1,1,1], [2,2,2], [3,3], and [4]. Each diagonal contains identical elements throughout, confirming diagonal consistency.
matrix = [[1,2],[2,2]]falseThe main diagonal running from position (0,0) to (1,1) contains elements [1,2]. Since 1 ≠ 2, the diagonal is not uniform, so the matrix does not satisfy diagonal consistency.
matrix = [[1,2,3],[4,1,2],[5,4,1]]trueAll diagonals have uniform values: [5], [4,4], [1,1,1], [2,2], [3]. The matrix is diagonally consistent.
Constraints