def solve(arr, n):
# Initialize two pointers, one at the beginning and one at the end of the array.
i = 0
j = n - 1
# Iterate until the two pointers meet.
while i < j:
# If the element at the current index is 1 and the element at the end of the array is 0,
# swap the two elements.
if arr[i] == 1 and arr[j] == 0:
arr[i], arr[j] = arr[j], arr[i]
# Move the left pointer one position to the right.
i += 1
# Move the right pointer one position to the left.
j -= 1
# If the element at the current index is 0, move the left pointer one position to the right.
elif arr[i] == 0:
i += 1
# If the element at the end of the array is 1, move the right pointer one position to the left.
elif arr[j] == 1:
j -= 1
# Example usage
arr = [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1]
solve(arr, len(arr))
print(arr) # Output: [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1]