Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Fix the first element of the hidden sequence to any value x and ignore the given bounds. Notice that we can then determine all the other elements of the sequence by using the differences array.
We will also be able to determine the difference between the minimum and maximum elements of the sequence. Notice that the value of x does not affect this.
We now have the ‘range’ of the sequence (difference between min and max element), we can then calculate how many ways there are to fit this range into the given range of lower to upper.
Answer is (upper - lower + 1) - (range of sequence)