Check Whether a Delivery Van Can Handle Every Pickup and Dropoff
Last updated: November 29, 2026
Quick Overview
A van with a seat-like package capacity drives one way along a route. Given trips as (packages, pickup_mile, dropoff_mile), return True if the van never carries more than its capacity at any point.
Amazon
November 29, 20260
0
0 solved
A van with a seat-like package capacity drives one way along a route. Given trips as (packages, pickup_mile, dropoff_mile), return True if the van never carries more than its capacity at any point.
An Amazon online assessment problem rooted in last-mile routing for Amazon Flex style vans. The grader checks a sweep-line or difference-array approach and the subtle rule that packages dropped at mile m free space before packages picked up at mile m.
What the Interviewer Expects
- Convert trips to load change events
- Use a difference array when miles are small, or sorted events otherwise
- Process dropoffs before pickups at the same mile
- Track running load and compare with capacity
- State complexity for both variants
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
- What if miles go up to 1e9 so a difference array is too large?
- Return the first mile where capacity is exceeded.
- What if the van can do multiple loops of the route?
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: trips as list of [count, start, end] with 0 <= start < end <= 1000, and integer capacity. Packages are on board for miles in [start, end). Output: True if load never exceeds capacity....
High-Level Design
Each trip adds count at mile start and removes it at mile end. Accumulate these as a difference array delta, then take prefix sums: the running value at mile m is the load while driving mile m...