Skip to content

Practice Difference Between Ones and Zeros in Row and Column

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2482
LeetCode Problem

Difference Between Ones and Zeros in Row and Column

Problem Statement

For each cell (i,j) of binary grid, add the number of ones in row i and column j, then subtract the number of zeros in that row and column. Return the matrix of these differences. The current cell participates once in its row count and once in its column count.

Source: Difference Between Ones and Zeros in Row and Column on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[0,1,1],[1,0,1],[0,0,1]]
Output
[[0,0,4],[0,0,4],[-2,-2,2]]

# Example 2

Input
grid = [[1,1,1],[1,1,1]]
Output
[[5,5,5],[5,5,5]]

Constraints

m == grid.length
n == grid[i].length
1 <= m, n <= 10^5
1 <= m * n <= 10^5
grid[i][j] is either 0 or 1.

Related LeetCode Problems

Practice more problems similar to Difference Between Ones and Zeros in Row and Column.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.