Leetcode in Java && Oracle
422 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2022-01-22_21-41-11.png
34.2 KB
#medium

#N2145. Count the Hidden Sequences
problem link

#solution
class Solution {
public int numberOfArrays(int[] differences, int lower, int upper) {
long min = 0, max = 0, curr = 0;

for(int d: differences){
curr += d;
min = Math.min(min, curr);
max = Math.max(max, curr);
}

long rangeDifference = (upper-lower) - (max-min) + 1;
return (int)Math.max(rangeDifference, 0);
}
}