Leetcode Problem 2319. Check if Matrix Is X-Matrix
2319. Check if Matrix Is X-Matrix
AI Mock Interview
Leetcode Solutions
Check Diagonals and Non-Diagonal Elements
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Iterate over each element in the matrix using two nested loops.
For each element at position (i, j), check if it's on the primary diagonal (i == j) or the secondary diagonal (i + j == n - 1).
If the element is on a diagonal, check that it is non-zero. If any diagonal element is zero, return false.
If the element is not on a diagonal, check that it is zero. If any non-diagonal element is non-zero, return false.
If all checks pass, return true.
Check Diagonals First, Then Validate Non-Diagonal Elements
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...