Minimum Delivery Vans to Carry Package Pairs Under a Weight Limit

Last updated: November 29, 2026

Quick Overview

Each delivery van can carry at most two packages and at most a weight limit W in total. Given package weights (each at most W), return the minimum number of vans needed to carry every package.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Each delivery van can carry at most two packages and at most a weight limit W in total. Given package weights (each at most W), return the minimum number of vans needed to carry every package.

A greedy two-pointer problem in the style of Amazon last-mile logistics assessments. The grader checks that you sort, pair the heaviest remaining package with the lightest when possible, and can justify why the greedy is optimal.

What the Interviewer Expects
  • Sort weights first
  • Use two pointers from both ends
  • Always place the heaviest package, pairing it with the lightest when they fit
  • Give an exchange argument for optimality
  • Handle a single package and all-heavy input
Key Topics to Cover
Greedy
Two Pointers
Sorting
Exchange Argument
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 a van can carry up to k packages instead of two?
  • How would you return the actual pairings?
  • What if weights are integers in a small range; can you avoid the sort?
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

Weights is a non-empty list of positive ints, each <= W. A van holds one or two packages whose sum is <= W. Return the minimum number of vans....

High-Level Design

Sort ascending. Let i point to the lightest and j to the heaviest. The heaviest package must ride somewhere; the best partner it could possibly take is the lightest one. If w[i] + w[j] <= W, put the...


Submit Your Answer
Markdown supported