Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Assuming a 0-indexed matrix, for a given cell on row i and column j, it is in a diagonal if and only if i == j or i == n - 1 - j.
We can then iterate through the elements in the matrix to check if all the elements in the diagonals are non-zero and all other elements are zero.