Ad
  • Default User Avatar

    When you remove element from the beginning (or from the middle) every element on the right is shifted to the left by one.
    Then you continue your loop but all the indexes on the right are messed up.
    Try starting from the right side.