Your code seems mostly correct, but I think you might encounter an Index out of Bounds error, because you are comparing (list[i]) with the next element (list[i+1]). This means when i reaches the second-to-last element (i = lastPosition - 1), you’ll be trying to access list[i+1], which is out of bounds.