def push_zeros_to_end(arr):
# Index to place the next non-zero element
non_zero_index = 0
# Traverse the array
for i in range(len(arr)):
if arr[i] != 0:
# Swap non-zero element with the element at non_zero_index
arr[non_zero_index], arr[i] = arr[i], arr[non_zero_index]
non_zero_index += 1
return arr
# Example usage
array = [0, 1, 0, 3, 12]
result = push_zeros_to_end(array)
print(result) # Output: [1, 3, 12, 0, 0]