Match the Most Customers to Gift Boxes Large Enough for Them

Last updated: November 29, 2026

Quick Overview

During a holiday promotion each customer i needs a gift box of size at least need[i], and the warehouse has boxes with sizes box[j], each usable once. Return the maximum number of customers who can each receive one suitable box.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


During a holiday promotion each customer i needs a gift box of size at least need[i], and the warehouse has boxes with sizes box[j], each usable once. Return the maximum number of customers who can each receive one suitable box.

An Amazon phone screen greedy question. The interviewer wants the sort-both, two-pointer match and a one-line exchange argument for why giving each customer the smallest box that fits never hurts.

What the Interviewer Expects
  • Sorts both lists
  • Uses two pointers to match smallest fitting box
  • Gives an exchange argument for greedy optimality
  • Runs in O(n log n + m log m)
  • Handles empty lists
Key Topics to Cover
greedy
sorting
two pointers
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 customer can take up to two boxes whose sizes add up?
  • Maximize the total size of needs served instead of the count.
  • Boxes arrive in a stream: can you serve online?
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: lists need and box of positive integers. Output: max number of disjoint (customer, box) pairs with box >= need....

High-Level Design

Sort both ascending. Walk boxes from smallest; keep a pointer to the smallest unserved need. If the current box fits that need, assign it and advance the need pointer; otherwise this box fits nobody r...


Submit Your Answer
Markdown supported