CRED MINT Off-Campus OA (2024) | Check if Matrix Is X-Matrix

Question · Posted Jun 2026

Problem Statement A square matrix is called an X-Matrix if: Every element on the primary diagonal (i == j) is non-zero. Every element on the secondary diagonal (i + j == n - 1) is non-zero. All other elements are zero. Return true if the given matrix is an X-Matrix, otherwise return false. Example Input grid = [  [2,0,0,1],  [0,3,1,0],  [0,5,2,0],  [4,0,0,2] ] Output true Explanation The diagonal elements are: Primary Diagonal   : 2, 3, 2, 2 Secondary Diagonal ...

The full answer & interview discussion are available to premium members.

Log in Create a free account