Car Fleet
Practice this coding question on Coding Gurukul.
Problem statement
A single-lane road leads to a checkpoint. Vehicles travel at fixed speeds until they catch a vehicle ahead; overtaking is forbidden, so they then share that slower vehicle's arrival time and form a fleet. Your task Count how many fleets reach target. A fleet may contain one vehicle. Cars that meet exactly at the destination count as the same fleet. Important details Initial positions are distinct and below target. Pair each position with its own speed even when sorting. A faster vehicle behind may merge with a fleet ahead, but cannot pass it. Compare arrival times accurately without rounding. Worked example With target 10, positions [0, 4] and speeds [2, 1], the rear car would arrive in 5 time units and the front in 6. It catches the front before the checkpoint, giving one fleet.
Input format
First line: n target. Next line: n positions. Final line: n speeds.
Output format
Print the fleet count.
Constraints
1 <= n <= 100000; 0 <= positions < target <= 1000000; 1 <= speeds <= 1000000; positions are distinct.
Sample input
2 10 0 4 2 1
Sample output
1
Sign in to run or submit a solution in C++, Java or Python.