Check diagonal equality in a matrix
MetaMachine Learning Engineer · Technical ScreenLast updated
This question evaluates skill in matrix manipulation and algorithmic reasoning, specifically understanding diagonal traversal, equality checks, and handling boundary conditions such as empty matrices, single-row or single-column inputs, and negative values.
Given an m x n integer matrix, determine whether every top-left to bottom-right diagonal contains identical values (all elements along each such diagonal are equal). Provide an O(mn) solution, discuss space trade-offs, and cover edge cases such as empty matrices, single row/column, and negative values.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.