from typing import List
def remove_zeros_inplace(array: List[int]) -> None:
Removes zeros from array.
Saves ordering of non-zero elements.
Use O(N) time complexity.
Uses O(1) additional memory complexity (works inplace)
Intended use:
array = [0, 1, 0, 2, 0, 3, 0]
remove_zeros_inplace(array)
print(array) # prints [1, 2, 3]
This problem asks you to remove all zeros from an array in place while preserving the relative order of the non-zero elements, using O(N) time and O(1) extra space. The standard solution uses a two-pointer approach: one pointer scans the array and another tracks the next write position for non-zero values. Each non-zero element is copied forward, and the remaining tail is effectively discarded. It is a classic test of in-place array manipulation and fast/slow pointer technique.