#139Medium#16 in Nutanix's list· asked at 2 companies
Car Fleet
Hosted on LeetCode
Solve it on LeetCode, track it here.
This problem's full statement lives on LeetCode. Open it in a new tab, then come back to mark it solved, add notes and keep your streak.
LeetCode Premium locked?
Most company-tagged LeetCode problems are behind Premium. If you have ChatGPT Plus or Claude Pro, ask it for the full statement, examples and constraints. The buttons below open a chat with the prompt already filled in.
What we know
Example 1
Input: target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3] Output: 3
Cars at 10 and 8 meet at 12; cars at 5 and 3 meet at 6; the car at 0 arrives alone.
Example 2
Input: target = 10, position = [3], speed = [3] Output: 1
Example 3
Input: target = 100, position = [0,2,4], speed = [4,2,1] Output: 1
Constraints
- •
n == position.length == speed.length - •
1 <= n <= 10^5,0 < target <= 10^6 - •
0 <= position[i] < target - •
All the values of
positionare unique. - •
0 < speed[i] <= 10^6