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

Answer · Posted Jun 2026

Approach Traverse every cell in the matrix. For each position (i, j): Check whether it belongs to either diagonal. If it is on a diagonal, the value must be non-zero. Otherwise, the value must be zero. If any condition is violated, return false. If all cells satisfy the conditions, return true. Strategy Let n be the matrix size. Iterate through every cell. Determine whether the cell lies on: Primary diagonal → i == j Secondary diagonal → i + j ...

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

Log in Create a free account