We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4ff333c commit f3d7ef5Copy full SHA for f3d7ef5
3355-zero-array-transformation-i/3355-zero-array-transformation-i.java
@@ -0,0 +1,28 @@
1
+class Solution {
2
+ public boolean isZeroArray(int[] nums, int[][] queries) {
3
+ // Sweep Line ALgo :-
4
+ int n = nums.length;
5
+
6
+ int[] line = new int[n+1];
7
8
+ for(int[] query : queries){
9
+ line[query[0]]--;
10
+ line[query[1]+1]++;
11
+ }
12
13
+ for(int i=1;i<n;i++){
14
+ line[i] = line[i]+line[i-1];
15
16
17
+ for(int i=0;i<n;i++){
18
+ nums[i] = line[i]+nums[i];
19
+ if(nums[i]<0){
20
+ nums[i]=0;
21
22
+ if(nums[i]>0){
23
+ return false;
24
25
26
+ return true;
27
28
+}
0 commit comments