-
Notifications
You must be signed in to change notification settings - Fork 161
/
cells-with-odd-values-in-a-matrix.md
33 lines (28 loc) · 1.58 KB
/
cells-with-odd-values-in-a-matrix.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<p>Given <code>n</code> and <code>m</code> which are the dimensions of a matrix initialized by zeros and given an array <code>indices</code> where <code>indices[i] = [ri, ci]</code>. For each pair of <code>[ri, ci]</code> you have to increment all cells in row <code>ri</code> and column <code>ci</code> by 1.</p>
<p>Return <em>the number of cells with odd values</em> in the matrix after applying the increment to all <code>indices</code>.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2019/10/30/e1.png" style="width: 600px; height: 118px;" />
<pre>
<strong>Input:</strong> n = 2, m = 3, indices = [[0,1],[1,1]]
<strong>Output:</strong> 6
<strong>Explanation:</strong> Initial matrix = [[0,0,0],[0,0,0]].
After applying first increment it becomes [[1,2,1],[0,1,0]].
The final matrix will be [[1,3,1],[1,3,1]] which contains 6 odd numbers.
</pre>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2019/10/30/e2.png" style="width: 600px; height: 150px;" />
<pre>
<strong>Input:</strong> n = 2, m = 2, indices = [[1,1],[0,0]]
<strong>Output:</strong> 0
<strong>Explanation:</strong> Final matrix = [[2,2],[2,2]]. There is no odd number in the final matrix.
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 50</code></li>
<li><code>1 <= m <= 50</code></li>
<li><code>1 <= indices.length <= 100</code></li>
<li><code>0 <= indices[i][0] < n</code></li>
<li><code>0 <= indices[i][1] < m</code></li>
</ul>