File tree 2 files changed +45
-1
lines changed
2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,883 LeetCode solutions in JavaScript
1
+ # 1,884 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1877
1877
3341|[ Find Minimum Time to Reach Last Room I] ( ./solutions/3341-find-minimum-time-to-reach-last-room-i.js ) |Medium|
1878
1878
3342|[ Find Minimum Time to Reach Last Room II] ( ./solutions/3342-find-minimum-time-to-reach-last-room-ii.js ) |Medium|
1879
1879
3343|[ Count Number of Balanced Permutations] ( ./solutions/3343-count-number-of-balanced-permutations.js ) |Hard|
1880
+ 3355|[ Zero Array Transformation I] ( ./solutions/3355-zero-array-transformation-i.js ) |Medium|
1880
1881
3356|[ Zero Array Transformation II] ( ./solutions/3356-zero-array-transformation-ii.js ) |Medium|
1881
1882
3375|[ Minimum Operations to Make Array Values Equal to K] ( ./solutions/3375-minimum-operations-to-make-array-values-equal-to-k.js ) |Easy|
1882
1883
3392|[ Count Subarrays of Length Three With a Condition] ( ./solutions/3392-count-subarrays-of-length-three-with-a-condition.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 3355. Zero Array Transformation I
3
+ * https://leetcode.com/problems/zero-array-transformation-i/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an integer array nums of length n and a 2D array queries, where
7
+ * queries[i] = [li, ri].
8
+ *
9
+ * For each queries[i]:
10
+ * - Select a subset of indices within the range [li, ri] in nums.
11
+ * - Decrement the values at the selected indices by 1.
12
+ *
13
+ * A Zero Array is an array where all elements are equal to 0.
14
+ *
15
+ * Return true if it is possible to transform nums into a Zero Array after processing all the
16
+ * queries sequentially, otherwise return false.
17
+ */
18
+
19
+ /**
20
+ * @param {number[] } nums
21
+ * @param {number[][] } queries
22
+ * @return {boolean }
23
+ */
24
+ var isZeroArray = function ( nums , queries ) {
25
+ const maxDecrements = new Array ( nums . length ) . fill ( 0 ) ;
26
+
27
+ for ( const [ left , right ] of queries ) {
28
+ maxDecrements [ left ] ++ ;
29
+ if ( right + 1 < nums . length ) {
30
+ maxDecrements [ right + 1 ] -- ;
31
+ }
32
+ }
33
+
34
+ let currentDecrements = 0 ;
35
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
36
+ currentDecrements += maxDecrements [ i ] ;
37
+ if ( nums [ i ] > currentDecrements ) {
38
+ return false ;
39
+ }
40
+ }
41
+
42
+ return true ;
43
+ } ;
You can’t perform that action at this time.
0 commit comments