Hi,
At 19:00
If we encounter a -ve number ,we remove previous number. But it can be possible that the previous number be the startting point.
Then Why we are removing previous number?
Starting point doubt
hello @vatsal50
pref is array that maintains prefix sum
now we are looking for some subarray [j+1…i]
sum =pref[i]-pref[j] || i> j
such that sum >= k right ?
now observe one thing that pref[j] is with negative sign.
so if we get pref[j1] and pref[j2] j1 < j2 and pref[j1] > pref[j2]
then j2 will be better option right? becuase its with negative sign and the lesser its magnitude the less it will subtract from pref[i] and hence sum will be more positive
and that is reason why we are popping greater values from dequeue if next element has lesser value (in magnitude)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.