sir i am not able to understand why you write
currentelement =cumsum[j]- cumsum[i-1] ;
why you don’t write
currentelement =cumsum[j]- cumsum[i] ;
Instead of cumsum[i] why you write cumsum[i-1] while calculate current element sum
this will not give desired results
for ex
if arr=[1,2,3,4,5,6]
then cumsum=[1,3,6,10,15,21]
now if you want to find sum of subarray from i=2 to j=4
means sum of (3,4,5)
using currentelement =cumsum[j]- cumsum[i] ;
we get 15-6=9 which is is wrong
correct is currentelement =cumsum[j]- cumsum[i-1] ;
15-3=12 ;