Will it not fail sum=cumSum[j]-cumSum[i-1] at i=0?

when we find sum then why
sum=cumSum[j]-cumSum[i-1] at i=0
this does not fail here in your code array should go out of bound and use any garbage value?

yes there is slight bit of problem in the video, it will be rectified soon.