Tap here to switch tabs
Problem
Submissions

Problem: Car Fleet

med
30 min
Try to solve the Car Fleet problem.

Statement

You are given a destination point target on a one lane road. There are n cars, where car i starts at position position[i] and moves toward target at constant speed speed[i].

A car cannot pass another car. If a faster car catches up to a slower car ahead of it, the faster car must slow down and they continue together at the slower car’s speed. Such a group of one or more cars traveling together is called a fleet.

Return the number of distinct car fleets that will arrive at target.

Note: A fleet may form exactly at target.

Constraints:

  • n == position.length == speed.length

  • 11 \leq n 105\leq 10^5

  • 0<0 < target 106\leq 10^6

  • 00 \leq position[i] << target

  • All values in position are unique

  • 0<0 < speed[i] 106\leq 10^6

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths
Tap here to switch tabs
Problem
Submissions

Problem: Car Fleet

med
30 min
Try to solve the Car Fleet problem.

Statement

You are given a destination point target on a one lane road. There are n cars, where car i starts at position position[i] and moves toward target at constant speed speed[i].

A car cannot pass another car. If a faster car catches up to a slower car ahead of it, the faster car must slow down and they continue together at the slower car’s speed. Such a group of one or more cars traveling together is called a fleet.

Return the number of distinct car fleets that will arrive at target.

Note: A fleet may form exactly at target.

Constraints:

  • n == position.length == speed.length

  • 11 \leq n 105\leq 10^5

  • 0<0 < target 106\leq 10^6

  • 00 \leq position[i] << target

  • All values in position are unique

  • 0<0 < speed[i] 106\leq 10^6

Unlock AI-Powered LearningUpgrade to smarter learning with instant explanations of Ask Agent, Personalized Interview Prep, Real-World Projects, 3 AI Mock Interviews per month, and Personalized Paths