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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

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
Sweep Line
Difference Array
Events
Prefix Sums
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported