LeetCode Day 18: Special Positions in Binary Matrix

Day 18/30 – LeetCode streak Problem: Special Positions in a Binary Matrix A position '(i, j)' is special if 'mat[i][j] == 1', and every other element in row 'i' and column 'j' is '0'. Core idea - Precompute how many '1's each row and each column contains. - Then a cell '(i, j)' is special if:  - 'mat[i][j] == 1'  - 'rowSum[i] == 1'  - 'colSum[j] == 1'. - Time: 'O(m × n)' – one full pass to compute sums, one to count special cells. - Space: 'O(m + n)' for 'rowSum' and 'colSum'. Day 18 takeaway: This is a clean pattern: precompute per-row and per-column counts once, then answer each cell’s question in 'O(1)' using those arrays instead of re-scanning its whole row and column. #leetcode #dsa #java #matrix #consistency

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories