I don’t understand the code mention in video.
first we store the cumsum[0] = a[0], that means the first value is goint to store in the cumsum first index. But the arrays elements is readed by 1 <n, so it means that the array a will store the value from to 1 < n, then how a[0] index is readed to store in the cumsum at first postition
Maximum subarrays problem using the cumaltive sum
Hey @Vikaspal Let me describe how we are making the cumsum array.
Now both the arrays are indexed 0 based.
The statement we are using to build the cum sum array is:-
if(i==0) cumsum[i]=A[i];
else cumsum[i]=cumsum[i-1]+A[i];
We are considering the case for 0 separately because there is no position referring to cumsum[-1] and it will throw segmentation fault.
So cumsum[i] does store the value of sum of all elements upto index i in the original array but because we are using 0 based indexing , we can also say that cumsum[i] is storing the sum of first i+1 elements in the original array, so cumsum[n-1] stores the sum of n elements.
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.