Array Out of bound

When i=0 shouldnt cumSum[i-1] give an error for going out of bounds?

Will i get an answer?

hello @vipulch

yeah right , but some modern compiler allows negative indexing so u might not see any bound error.
but its always a good practice to handel such cases seprately and avoid any negative indexing.

for this problem use if and else to handle it ->

if(i>0)
curr_sum= csum[ j] -csum[i-1];
else 
curr_sum= csum[ j]