cheetcode

26. Car FleetMedium

Count how many car fleets arrive at the destination.

There are n cars going to the same destination along a one-lane road.

If a faster car catches up to a slower car, it becomes part of the same fleet. Return the number of fleets that arrive at the target.

Examples

Input: target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]
Output: 3
Input: target = 10, position = [3], speed = [3]
Output: 1

Constraints

  • 1 <= n <= 100,000
  • 0 < target <= 1,000,000
  • 0 <= position[i] < target
  • 1 <= speed[i] <= 1,000,000