|
| 1 | +<h2><a href="https://leetcode.com/problems/range-addition">370. Range Addition</a></h2><h3>Medium</h3><hr><p>You are given an integer <code>length</code> and an array <code>updates</code> where <code>updates[i] = [startIdx<sub>i</sub>, endIdx<sub>i</sub>, inc<sub>i</sub>]</code>.</p> |
| 2 | + |
| 3 | +<p>You have an array <code>arr</code> of length <code>length</code> with all zeros, and you have some operation to apply on <code>arr</code>. In the <code>i<sup>th</sup></code> operation, you should increment all the elements <code>arr[startIdx<sub>i</sub>], arr[startIdx<sub>i</sub> + 1], ..., arr[endIdx<sub>i</sub>]</code> by <code>inc<sub>i</sub></code>.</p> |
| 4 | + |
| 5 | +<p>Return <code>arr</code> <em>after applying all the</em> <code>updates</code>.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | +<img alt="" src="https://assets.leetcode.com/uploads/2021/03/27/rangeadd-grid.jpg" style="width: 413px; height: 573px;" /> |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> length = 5, updates = [[1,3,2],[2,4,3],[0,2,-2]] |
| 12 | +<strong>Output:</strong> [-2,0,3,5,3] |
| 13 | +</pre> |
| 14 | + |
| 15 | +<p><strong class="example">Example 2:</strong></p> |
| 16 | + |
| 17 | +<pre> |
| 18 | +<strong>Input:</strong> length = 10, updates = [[2,4,6],[5,6,8],[1,9,-4]] |
| 19 | +<strong>Output:</strong> [0,-4,2,2,2,4,4,-4,-4,-4] |
| 20 | +</pre> |
| 21 | + |
| 22 | +<p> </p> |
| 23 | +<p><strong>Constraints:</strong></p> |
| 24 | + |
| 25 | +<ul> |
| 26 | + <li><code>1 <= length <= 10<sup>5</sup></code></li> |
| 27 | + <li><code>0 <= updates.length <= 10<sup>4</sup></code></li> |
| 28 | + <li><code>0 <= startIdx<sub>i</sub> <= endIdx<sub>i</sub> < length</code></li> |
| 29 | + <li><code>-1000 <= inc<sub>i</sub> <= 1000</code></li> |
| 30 | +</ul> |
0 commit comments