Car Fleet
Medium · Stack & Monotonic Stack · about 20 minutes
Asked at Google, Amazon, Microsoft, Bloomberg, Meta.
n cars drive to target on a one-lane road. Car i starts at position[i] (all distinct) with speed speed[i]. A car can't pass the one ahead; when it catches up it slows down and they move together as a fleet. A car catching a fleet exactly at target joins it. Return the number of fleets that arrive at the target.