Code not behaving properly in online coding blocks ide but runs smoothly in my offline ide

Code not behaving properly in online coding blocks ide but runs smoothly in my offline ide. Try running it for the input values shown in the picture (the same used in the video lecture).

hello @anshufirefox

for(int i=0;i<N;i++)
{
  for(int j=i;j<N;j++)
  {
     current= cs[j]-cs[i-1];//handle i==0 case seprately
     if(current>maxm)
     maxm=current;
  }
}

handle i==0 case seprately

Yeah I was wondering about the same, But Sir in the video lecture code did not handle it and yet his code was running smoothly, why? Given that he used coding blocks ide and I am using it too.

Also, why is my offline ide not giving nay error? In i = 0 case, cs[i-1] means cs[-1] which should ideally result in some form of memory error. But nothing happened as such in my offline c++ ide

@anshufirefox

thats compiler specific thing, some compilers allow negative index access and some may not.

but always add ur own if statement to avoid negative index access

Got it, Thank You so much. Please help me close this thread by sending the rating link

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.