Dashboard
LC #853

Car Fleet

Pattern · ?

Problem

Find how many car fleets will arrive at the destination. Cars cannot pass each other.

Constraints

  • 1 ≤ n ≤ 10⁵
  • 0 < target ≤ 10⁶
  • 0 ≤ position[i] < target
  • 0 < speed[i] ≤ 10⁶

Example

Input
target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]
Output
3
Why
The cars starting at 10 and 8 form a fleet. The car at 5 forms a fleet. The cars at 0 and 3 form a fleet. Total 3 fleets.

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗