Car Fleet Problem
Car Fleet Problem — ExecCode Medium DSA Practice
Solve the Car Fleet problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
There are n cars going to the same destination on a one-lane road. Given positions and speeds, return the number of car fleets that will arrive at the destination.
Examples
Input target = 12, position = [10, 8, 0, 5, 3, 6], speed = [2, 4, 1, 1, 3, 2]; Output 4. Input target = 12, position = [10, 8, 0, 5, 3], speed = [2, 4, 1, 1, 3]; Output 3
Constraints
n == position.length == speed.length 1 ≤ n ≤ 10⁵
Practice Car Fleet free on ExecCode. Browse DSA problems, topic map, and placement guides.