The problem with counting forward is that removing an index causes all future indices to shift down by 1.
The traditional way to do this in all programming languages is to iterate through your array in reverse order from MaxElements to 0. If you remove an element when counting in reverse it doesn’t affect the indices of the remaining elements in the array.