this line states[i] = 0; doesn't make sense inside this condition, because you already know that the value in states[i] is 0.
And as for the exception - if you know i is smaller than the array's length, it means that i+1 must be equal to the array's length to throw that exception - so, guessing that this i is a for loop variable, you need the loop to stop one step before - so for(var i = 0; i < arr.Length - 1; i++) {/* do stuff here */}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
to check the neighbors of the element in the array
this line
states[i] = 0;
doesn't make sense inside this condition, because you already know that the value instates[i]
is0
.And as for the exception - if you know
i
is smaller than the array's length, it means that i+1 must be equal to the array's length to throw that exception - so, guessing that this i is a for loop variable, you need the loop to stop one step before - sofor(var i = 0; i < arr.Length - 1; i++) {/* do stuff here */}