Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Pair positions with speeds and sort by position. Traverse from the car nearest to target backward, computing each car travel time. If a car needs more time than the fleet ahead, it forms a new fleet; otherwise it merges into the existing fleet.
Going right to left ensures every car only interacts with the nearest fleet ahead. Non-increasing fleet times represent merges, while an increased time starts a new fleet.
Updated Feb 2026