Practice Car Fleet II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
cars[i] = [position,speed] describes point-like cars moving along one lane in the same direction, ordered by increasing initial position. When cars meet, they form a fleet moving at the slowest original speed in that fleet. Return each car first collision time with the car or fleet ahead, or -1 if it never collides. Error within 10^-5 is accepted.
Source: Car Fleet II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
cars = [[1,2],[2,1],[4,3],[7,2]]
Output
[1.00000,-1.00000,3.00000,-1.00000]
# Example 2
Input
cars = [[3,4],[5,4],[6,3],[9,1]]
Output
[2.00000,1.00000,1.50000,-1.00000]
Constraints
1 <= cars.length <= 10^5
1 <= positioni, speedi <= 10^6
positioni < positioni+1
Related LeetCode Problems
Practice more problems similar to Car Fleet II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.