Answer: LEGION SYSTEMS Hiring Challenge | Off-Campus OA (2021) | Matrix Counting

Answer · Posted Jun 2026

Approach Instead of updating the entire matrix: Maintain count of increments for every row. Maintain count of increments for every column. A cell (i,j) value equals: rowCount[i] + colCount[j] If the sum is odd, increment the answer. Java Code class Solution { public int oddCells(int m, int n, int[][] indices) { int[] rowCount = new int[m]; int[] colCount = new int[n]; for (int[] idx : indices) { rowCount[idx[0]]++; colCount[idx[1]]++; } int oddCount = 0; for (int i = 0; i ...

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

Log in Create a free account