Tap here to switch tabs
Problem
Submissions

Problem: Difference Between Ones and Zeros in Row and Column

Try to solve the Difference Between Ones and Zeros in Row and Column problem.

Statement

You are given a 0-indexed m×nm \times n binary matrix grid. Compute a 0-indexed m×nm \times n difference matrix diff\text{diff}.

For every cell (i,j)(i, j), the element diff[i][j]\text{diff}[i][j] is calculated as:

  • Let the number of ones in the ithi^{th} row be onesRow[i]\text{onesRow}[i].

  • Let the number of ones in the jthj^{th} column be onesCol[j]\text{onesCol}[j].

  • Let the number of zeros in the ithi^{th} row be zerosRow[i]\text{zerosRow}[i].

  • Let the number of zeros in the jthj^{th} column be zerosCol[j]\text{zerosCol}[j].

  • diff[i][j]=onesRow[i]+onesCol[j]−zerosRow[i]−zerosCol[j]\text{diff}[i][j] = \text{onesRow}[i] + \text{onesCol}[j] - \text{zerosRow}[i] - \text{zerosCol}[j]

Constraints:

  • m=grid.lengthm = \text{grid.length}

  • n=grid[i].lengthn = \text{grid}[i].\text{length}

  • 1≤m,n≤1051 \leq m, n \leq 10^5

  • 1≤m×n≤1051 \leq m \times n \leq 10^5

  • grid[i][j]\text{grid}[i][j] is either 00 or 11.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Difference Between Ones and Zeros in Row and Column

Try to solve the Difference Between Ones and Zeros in Row and Column problem.

Statement

You are given a 0-indexed m×nm \times n binary matrix grid. Compute a 0-indexed m×nm \times n difference matrix diff\text{diff}.

For every cell (i,j)(i, j), the element diff[i][j]\text{diff}[i][j] is calculated as:

  • Let the number of ones in the ithi^{th} row be onesRow[i]\text{onesRow}[i].

  • Let the number of ones in the jthj^{th} column be onesCol[j]\text{onesCol}[j].

  • Let the number of zeros in the ithi^{th} row be zerosRow[i]\text{zerosRow}[i].

  • Let the number of zeros in the jthj^{th} column be zerosCol[j]\text{zerosCol}[j].

  • diff[i][j]=onesRow[i]+onesCol[j]−zerosRow[i]−zerosCol[j]\text{diff}[i][j] = \text{onesRow}[i] + \text{onesCol}[j] - \text{zerosRow}[i] - \text{zerosCol}[j]

Constraints:

  • m=grid.lengthm = \text{grid.length}

  • n=grid[i].lengthn = \text{grid}[i].\text{length}

  • 1≤m,n≤1051 \leq m, n \leq 10^5

  • 1≤m×n≤1051 \leq m \times n \leq 10^5

  • grid[i][j]\text{grid}[i][j] is either 00 or 11.