Linear-Time Algorithm