Problem
Some cars drive on a one-lane road to the same destination. You get the integer target, which is the point of the destination on the road.
You also get two integer arrays, position and speed, of length n. Car i starts at the point position[i] and drives speed[i] units of distance in each hour.
A car cannot pass the car in front of it. When a faster car reaches a slower car, the faster car changes to the speed of the slower car. From that time, the two cars drive together.
A car fleet is a group of one or more cars that drive together at the same point and the same speed. A car that reaches a fleet exactly at the destination is part of that fleet.
Return the number of car fleets that arrive at the destination.
Example 1
- Input:
- target = 20, position = [0,8,14], speed = [4,2,1]
- Output:
- 1
- Explanation:
- The cars at 8 and 14 both need 6 hours, so they meet exactly at the destination. Alone, the car at 0 needs only 5 hours, so it reaches them before the destination.
Example 2
- Input:
- target = 10, position = [2,6], speed = [1,4]
- Output:
- 2
- Explanation:
- The car at 6 arrives after 1 hour. The car at 2 arrives after 8 hours and never reaches the other car.
Example 3
- Input:
- target = 12, position = [10,7,4,0], speed = [1,2,2,3]
- Output:
- 3
Constraints
- n == position.length == speed.length
- 1 <= n <= 10^5
- 0 < target <= 10^6
- 0 <= position[i] < target
- All the values of position are different.
- 0 < speed[i] <= 10^6
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Car Fleet II
Coding
- Car Pooling
Coding
- Car Rental Optimization
Coding
- Race Car
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 853. Car Fleet
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source