I have some questions about this question (#13)! First, I know an error should happen from removing and skipping elements, BUT I cannot reproduce the error.
Also, why wouldn’t B also be correct, it says the same thing as E.
In Java, the for loop keeps updating, so when removing an element, the .size goes down by one, and when the for loop checks the condition, it checks against the updated size. So in java there will not be an index out of bounds error as i will not go past the newest size.
Whereas in Python, if you use for i in range…that is set up before the loop iterates, and if the list changes then i is still going to go through the range from before and you get index out of bounds in the python version.
@jeff.rhodes Hello again. we very much appreciate your keen bug detection skills. The way I read the question is that when an index is removed from the list each remaining element after the item that was removed will receive a new index.
{23, 5, 7, 9, 11}
23 is removed - each element has a new index
{5, 7, 9, 11}
5 is skipped since it is at index 1. 7 is now removed. New indices assigned.
{5, 9, 11}
5, 9 are skipped since it’s on its third pass. 11 is removed
{5, 9} is the result.
I hope that makes sense.
Also B is not correct because the array does not go out of bounds.