ASAPUtils Logo ASAPUtils
Week 3

Car Fleet

Car Fleet explained by sorting positions and comparing arrival times, with the no-passing insight, monotonic survivor stack, C++ and JavaScript solutions, complexity, and an interactive trace.

The problem

Cars drive toward one target on a one-lane road. A faster car that catches a slower car becomes part of its fleet and cannot pass it. Return how many fleets reach the target.

target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3] -> 3

Related Problems