The Car Fleet interview question asks you to find the number of "car fleets" that will arrive at a target destination. You are given the target distance, an array of position values, and an array of speed values for n cars. A car fleet is a group of one or more cars traveling at the same speed because a faster car caught up to a slower car ahead of it. Faster cars cannot pass slower ones; they simply slow down and join the fleet. This Car Fleet coding problem is about calculating time-to-destination and identifying collisions.
Companies like Google, Microsoft, and Meta use this to test a candidate's ability to process events based on their physical constraints. It evaluates whether you can recognize that the problem is best solved by processing cars from the one closest to the target backward. It tests your proficiency with sorting and stack-based logic.
This problem utilizes the Array, Monotonic Stack, Sorting, Stack interview pattern.
target = 12, position = [10, 8, 0, 5, 3], speed = [2, 4, 1, 1, 3]
When objects are moving in a line and cannot pass each other, always try to solve the problem by looking at the "leader" (the one furthest ahead). The behavior of everyone behind is restricted by the leaders.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximum Length of Semi-Decreasing Subarrays | Medium | Solve | |
| Finding the Number of Visible Mountains | Medium | Solve | |
| Max Chunks To Make Sorted | Medium | Solve | |
| The Number of Weak Characters in the Game | Medium | Solve | |
| Sum of Subarray Ranges | Medium | Solve |