#853

Car Fleet

specialist · 825 · lc medium +31 · 54.8% accepted · 4,271 likes · top 48%

Description

There are n cars driving toward the same destination target miles away. You are given two arrays position and speed, each of length n, where position[i] is the starting mile marker and speed[i] is the speed (in miles per hour) of car i.

No car can pass another car, but a faster car may catch up and form a fleet, traveling together at the slower car's speed.

A car fleet is a group of cars traveling together. A car that arrives at target at the same moment as a fleet is considered part of that fleet.

Return the number of fleets that reach the destination.

Code

1
2
3