Skip to content

Practice Check if Matrix Is X-Matrix

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2319
LeetCode Problem

Check if Matrix Is X-Matrix

Problem Statement

Return whether every cell on either main diagonal of square grid is nonzero and every cell outside those two diagonals is zero.

Source: Check if Matrix Is X-Matrix on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[2,0,0,1],[0,3,1,0],[0,5,2,0],[4,0,0,2]]
Output
true

# Example 2

Input
grid = [[5,7,0],[0,3,1],[0,5,0]]
Output
false

Constraints

n == grid.length == grid[i].length
3 <= n <= 100
0 <= grid[i][j] <= 10^5

Related LeetCode Problems

Practice more problems similar to Check if Matrix Is X-Matrix.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.