Index error doubt

When currentsum is calculated, for cases where i = 0, shouldn’t csum[i-1] throw an out of bounds error?

actualy sir starts loop from i=1
i=0 case is handled seperately outside the loop

i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved
if you have more doubts regarding this feel free to ask

Here the loop runs from i = 0 to n and the currentSum is calculated as cumSum[j] - cumSum[i-1]. for the first iteration of outer for loop, i = 0, so the computation made is cumSum[j] - cumSum[0-1]. How’s there no index error for cumSum[-1]?

okay
this is wrong
it will show error or not depend on machine
if this memory is allocated to program then there will be no error otherwise segmentation fault will be shown

From what I understand, when an array of size n is initialized, only indices 0 to n-1 are available for use, so how is the program able to access -1 index which doesn’t exist without error? If -1 is available too, it should have garbage value, not 0, right? Please clarify.

yes you are right you can use only from 0 to n-1

but arr[-1] may exist depend on machine
arr[-1] means going one step backward

this may give error on your machine try to avoid these things they are uncertain

yes it may contain garbage then currentsum is some negative no hence maxsum will not change

1 Like

Another doubt. How do I mark doubt as resolved? xD

do to your course
and then go to the this doubt there is a option to mark doubt as resolved