The Car Fleet II interview question is a much more complex version of the original. Instead of counting fleets at a target, you need to find the exact time each car will collide with the car in front of it. If a car never collides, the time is -1. This Car Fleet II coding problem involves dynamic collisions where a car might collide with a fleet that was already formed by two other cars.
Google uses this HARD-level problem to test a candidate's ability to use Monotonic Stacks for complex interval/event processing. It requires calculating not just if a collision happens, but when it happens, and whether that collision occurs before or after the target car has already merged into another fleet. It’s a test of high-level mathematical and algorithmic reasoning.
This uses the Array, Math, Monotonic Stack, Stack interview pattern.
Car 1 (lead): Speed 2. Car 2 (behind): Speed 4. Car 3 (furthest back): Speed 5.
Practice "Right-to-Left Monotonic Stack" problems. This is a common pattern for "what happens to me based on the people in front of me" scenarios.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Number of Visible People in a Queue | Hard | Solve | |
| Largest Rectangle in Histogram | Hard | Solve | |
| Number of Valid Subarrays | Hard | Solve | |
| Buildings With an Ocean View | Medium | Solve | |
| Sum of Subarray Ranges | Medium | Solve |