Skip to content

Commit 29a6281

Browse files
committed
Readme
1 parent c8c0efc commit 29a6281

File tree

1 file changed

+42
-0
lines changed
  • 1252-cells-with-odd-values-in-a-matrix

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<p>There is an <code>m x n</code> matrix that is initialized to all <code>0</code>&#39;s. There is also a 2D array <code>indices</code> where each <code>indices[i] = [r<sub>i</sub>, c<sub>i</sub>]</code> represents a <strong>0-indexed location</strong> to perform some increment operations on the matrix.</p>
2+
3+
<p>For each location <code>indices[i]</code>, do <strong>both</strong> of the following:</p>
4+
5+
<ol>
6+
<li>Increment <strong>all</strong> the cells on row <code>r<sub>i</sub></code>.</li>
7+
<li>Increment <strong>all</strong> the cells on column <code>c<sub>i</sub></code>.</li>
8+
</ol>
9+
10+
<p>Given <code>m</code>, <code>n</code>, and <code>indices</code>, return <em>the <strong>number of odd-valued cells</strong> in the matrix after applying the increment to all locations in </em><code>indices</code>.</p>
11+
12+
<p>&nbsp;</p>
13+
<p><strong class="example">Example 1:</strong></p>
14+
<img alt="" src="https://assets.leetcode.com/uploads/2019/10/30/e1.png" style="width: 600px; height: 118px;" />
15+
<pre>
16+
<strong>Input:</strong> m = 2, n = 3, indices = [[0,1],[1,1]]
17+
<strong>Output:</strong> 6
18+
<strong>Explanation:</strong> Initial matrix = [[0,0,0],[0,0,0]].
19+
After applying first increment it becomes [[1,2,1],[0,1,0]].
20+
The final matrix is [[1,3,1],[1,3,1]], which contains 6 odd numbers.
21+
</pre>
22+
23+
<p><strong class="example">Example 2:</strong></p>
24+
<img alt="" src="https://assets.leetcode.com/uploads/2019/10/30/e2.png" style="width: 600px; height: 150px;" />
25+
<pre>
26+
<strong>Input:</strong> m = 2, n = 2, indices = [[1,1],[0,0]]
27+
<strong>Output:</strong> 0
28+
<strong>Explanation:</strong> Final matrix = [[2,2],[2,2]]. There are no odd numbers in the final matrix.
29+
</pre>
30+
31+
<p>&nbsp;</p>
32+
<p><strong>Constraints:</strong></p>
33+
34+
<ul>
35+
<li><code>1 &lt;= m, n &lt;= 50</code></li>
36+
<li><code>1 &lt;= indices.length &lt;= 100</code></li>
37+
<li><code>0 &lt;= r<sub>i</sub> &lt; m</code></li>
38+
<li><code>0 &lt;= c<sub>i</sub> &lt; n</code></li>
39+
</ul>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Follow up:</strong> Could you solve this in <code>O(n + m + indices.length)</code> time with only <code>O(n + m)</code> extra space?</p>

0 commit comments

Comments
 (0)