So I know popping an element from an an array is O(n) since you have to shift all the elements over by one. BUT, what if you popped an element AND appended that same element to the back of the array, all in one line. Would this be constant operation O(1) since you don't have to shift anything? Please see my code below with the comment.
def moveZeroes(self, nums: List[int]) -> None:
index = 0
zeroes = nums.count(0)
counter = 0
while True:
if counter == zeroes:
break
if nums[index] == 0:
nums.append(nums.pop(index)) # THIS LINE RIGHT HERE
counter += 1
else:
index += 1