Dodomeki
Sign in

62. Car Fleets

Medium

A straight road has a finish line at alvo. Each car starts at position posicoes[i] and moves at constant speed velocidades[i]. If a car catches up to another, it starts moving at that car's pace, forming a fleet. Return how many fleets reach the finish line. The positions are distinct, and all cars start before the finish line.

Example 1
Input: alvo = 20, posicoes = [2, 10, 15], velocidades = [2, 2, 1]
Output: 2
Explanation: The car at 2 catches the one at 10; the cars at 10 and 15 arrive together as another fleet.
Example 2
Input: alvo = 12, posicoes = [3, 8], velocidades = [3, 1]
Output: 1
Constraints
  • 1 <= posicoes.length <= 10^5
  • posicoes.length = velocidades.length
  • 0 <= posicoes[i] < alvo <= 10^6
  • 1 <= velocidades[i] <= 10^6
ArraysSortingStack
Caso 1
alvo =
20
posicoes =
[2,10,15]
velocidades =
[2,2,1]
Expected =
2
Caso 2
alvo =
12
posicoes =
[3,8]
velocidades =
[3,1]
Expected =
1

Run checks these 2 cases. Submit runs all 6, including hidden ones.