Angad Sandhu
Search
Browse

853_Car_Fleet

Source name
853_Car_Fleet.py
# File: Leetcode/Solutions/853_Car_Fleet.py


"""
Problem Number: 853
Problem Name: Car Fleet
Difficulty: Medium
Tags: Array, Stack, Sorting, Monotonic Stack, Neetcode 150
Company (Frequency): Amazon, Google, Microsoft, Tesla
Leetcode Link: <https://leetcode.com/problems/car-fleet/description/>

DESCRIPTION

There are `n` cars going to the same destination along a one-lane road. The destination is `target` miles away.

You are given two integer arrays `position` and `speed`, both of length `n`, where `position[i]` is the position of the `ith` car and `speed[i]` is the speed of the `ith` car (in miles per hour).

A car can never pass another car ahead of it, but it can catch up to it and drive bumper to bumper at the same speed. The faster car will slow down to match the slower car's speed. The distance between these two cars is ignored (i.e., they are assumed to have the same position).

A car fleet is some non-empty set of cars driving at the same position and same speed. Note that a single car is also a car fleet.

If a car catches up to a car fleet right at the destination point, it will still be considered as one car fleet.

Return the number of car fleets that will arrive at the destination.
"""

Browse the library