|
| 1 | +<h2><a href="https://leetcode.com/problems/zero-array-transformation-i/">3355. Zero Array Transformation I</a></h2><h3>Medium</h3><hr><div><p>You are given an integer array <code>nums</code> of length <code>n</code> and a 2D array <code>queries</code>, where <code>queries[i] = [l<sub>i</sub>, r<sub>i</sub>]</code>.</p> |
| 2 | + |
| 3 | +<p>For each <code>queries[i]</code>:</p> |
| 4 | + |
| 5 | +<ul> |
| 6 | + <li>Select a subset of indices within the range <code>[l<sub>i</sub>, r<sub>i</sub>]</code> in <code>nums</code>.</li> |
| 7 | + <li>Decrement the values at the selected indices by 1.</li> |
| 8 | +</ul> |
| 9 | + |
| 10 | +<p>A <strong>Zero Array</strong> is an array where all elements are equal to 0.</p> |
| 11 | + |
| 12 | +<p>Return <code>true</code> if it is <em>possible</em> to transform <code>nums</code> into a <strong>Zero Array </strong>after processing all the queries sequentially, otherwise return <code>false</code>.</p> |
| 13 | + |
| 14 | +<p>A <strong>subset</strong> of an array is a selection of elements (possibly none) of the array.</p> |
| 15 | + |
| 16 | +<p> </p> |
| 17 | +<p><strong class="example">Example 1:</strong></p> |
| 18 | + |
| 19 | +<div class="example-block"> |
| 20 | +<p><strong>Input:</strong> <span class="example-io">nums = [1,0,1], queries = [[0,2]]</span></p> |
| 21 | + |
| 22 | +<p><strong>Output:</strong> <span class="example-io">true</span></p> |
| 23 | + |
| 24 | +<p><strong>Explanation:</strong></p> |
| 25 | + |
| 26 | +<ul> |
| 27 | + <li><strong>For i = 0:</strong> |
| 28 | + |
| 29 | + <ul> |
| 30 | + <li>Select the subset of indices as <code>[0, 2]</code> and decrement the values at these indices by 1.</li> |
| 31 | + <li>The array will become <code>[0, 0, 0]</code>, which is a Zero Array.</li> |
| 32 | + </ul> |
| 33 | + </li> |
| 34 | +</ul> |
| 35 | +</div> |
| 36 | + |
| 37 | +<p><strong class="example">Example 2:</strong></p> |
| 38 | + |
| 39 | +<div class="example-block"> |
| 40 | +<p><strong>Input:</strong> <span class="example-io">nums = [4,3,2,1], queries = [[1,3],[0,2]]</span></p> |
| 41 | + |
| 42 | +<p><strong>Output:</strong> <span class="example-io">false</span></p> |
| 43 | + |
| 44 | +<p><strong>Explanation:</strong></p> |
| 45 | + |
| 46 | +<ul> |
| 47 | + <li><strong>For i = 0:</strong> |
| 48 | + |
| 49 | + <ul> |
| 50 | + <li>Select the subset of indices as <code>[1, 2, 3]</code> and decrement the values at these indices by 1.</li> |
| 51 | + <li>The array will become <code>[4, 2, 1, 0]</code>.</li> |
| 52 | + </ul> |
| 53 | + </li> |
| 54 | + <li><strong>For i = 1:</strong> |
| 55 | + <ul> |
| 56 | + <li>Select the subset of indices as <code>[0, 1, 2]</code> and decrement the values at these indices by 1.</li> |
| 57 | + <li>The array will become <code>[3, 1, 0, 0]</code>, which is not a Zero Array.</li> |
| 58 | + </ul> |
| 59 | + </li> |
| 60 | +</ul> |
| 61 | +</div> |
| 62 | + |
| 63 | +<p> </p> |
| 64 | +<p><strong>Constraints:</strong></p> |
| 65 | + |
| 66 | +<ul> |
| 67 | + <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> |
| 68 | + <li><code>0 <= nums[i] <= 10<sup>5</sup></code></li> |
| 69 | + <li><code>1 <= queries.length <= 10<sup>5</sup></code></li> |
| 70 | + <li><code>queries[i].length == 2</code></li> |
| 71 | + <li><code>0 <= l<sub>i</sub> <= r<sub>i</sub> < nums.length</code></li> |
| 72 | +</ul> |
| 73 | +</div> |
0 commit comments