Cells with Odd Values in a Matrix - Problem
Given an m x n matrix initialized to all zeros, and a 2D array indices where each indices[i] = [ri, ci] represents a location to perform increment operations.
For each location indices[i], do both of the following:
- Increment all cells in row
ri - Increment all cells in column
ci
Return the number of cells with odd values in the matrix after applying all increment operations.
Input & Output
Example 1 — Basic Case
$
Input:
m = 2, n = 3, indices = [[0,1],[1,1]]
›
Output:
6
💡 Note:
Matrix starts as zeros. After [0,1]: increment row 0 and column 1. After [1,1]: increment row 1 and column 1 again. Final matrix [[1,3,1],[1,3,1]] has 6 odd values.
Example 2 — Single Operation
$
Input:
m = 2, n = 2, indices = [[1,1]]
›
Output:
2
💡 Note:
After [1,1]: increment row 1 and column 1. Final matrix [[0,1],[1,2]] has 2 odd values at positions (0,1) and (1,0).
Example 3 — No Operations
$
Input:
m = 2, n = 2, indices = []
›
Output:
0
💡 Note:
No operations performed, matrix remains all zeros, so 0 odd values.
Constraints
- 1 ≤ m, n ≤ 50
- 1 ≤ indices.length ≤ 100
- 0 ≤ ri < m
- 0 ≤ ci < n
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code