+ 1

Could anyone please help me understand the error in this code?

https://code.sololearn.com/c45N9xOP9o7u/?ref=app

14th Oct 2022, 4:18 PM
Hemasri Kottapalli
Hemasri Kottapalli - avatar
3 Réponses
+ 2
for(int i=0 ; i<(i+m)-1;i++) here condition i < (I+m) -1 will never end condition... edit: Learner🥇 also this will raise error int diff=chocs[(i+m)-1]-chocs[i]; when I=5 , then chocs[5+7-1] => chocs[11] , 11 index is out of bounds for array length 11.
14th Oct 2022, 4:23 PM
Jayakrishna 🇮🇳
+ 2
First of all thank you so much Jayakrishna🇮🇳 for always giving fast replies! I truly appreciate your help! But would you mind elaborating it?
14th Oct 2022, 4:28 PM
Hemasri Kottapalli
Hemasri Kottapalli - avatar
+ 1
Oh. Already added about when raising error in previous reply as edit. And if you are about condition then, i < i + m -1 here condition for any value of i, in each iteartion it increase by i++ so it will be like 0 < 0+7-1 => 0<6 true 1 < 1+7-1 => 1<7 true 2 < 2+7-1 => 2<8 true Hope it clears now.. ! ?...Learner🥇
14th Oct 2022, 4:38 PM
Jayakrishna 🇮🇳