Count the Delivery Van Convoys That Arrive at the Depot
Last updated: November 29, 2026
Quick Overview
Vans on a one-lane road head to a depot at mile target. Van i starts at position[i] with speed speed[i] and cannot pass; a faster van that catches a slower one slows down and they continue as one convoy. Return the number of convoys that arrive at the depot.
Amazon
November 29, 20260
0
0 solved
Vans on a one-lane road head to a depot at mile target. Van i starts at position[i] with speed speed[i] and cannot pass; a faster van that catches a slower one slows down and they continue as one convoy. Return the number of convoys that arrive at the depot.
An Amazon technical screen question about last-mile logistics that reduces to a monotonic stack of arrival times. The interviewer checks that you sort by position from closest to the depot and reason about who blocks whom.
What the Interviewer Expects
- Sorts vans by position descending
- Computes each van's solo arrival time
- Merges a van into the convoy ahead if it would arrive no later
- Counts convoys with a stack or running max
- Handles catching up exactly at the target
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the arrival time of each convoy.
- Vans can change lanes on a two-lane road: what changes?
- Return the time each van joins its convoy.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: target, lists position and speed (distinct positions, all < target, speeds positive). Output: number of convoys at arrival. Meeting exactly at the target counts as one convoy....
High-Level Design
Only vans ahead can block a van. Sort by position from nearest the depot to farthest and compute solo arrival time t = (target - position) / speed. Walk that order keeping the arrival time of the conv...