Assign Cookies to Maximize Satisfied Children

Quick Overview

Maximize satisfied children by greedily assigning sorted cookie sizes, with an exchange proof, empty-input handling, and optional assignment reconstruction.

Assign Cookies to Maximize Satisfied Children

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Each child has a minimum acceptable cookie size, and each cookie has a size. A child is satisfied by one cookie at least as large as that child's requirement. Each cookie can be assigned to at most one child. Return the maximum number of satisfied children. ### Clarifying Questions to Ask - Can each child receive at most one cookie, and are cookie sizes indivisible? - May the input arrays be sorted in place? ```hint Save large cookies when possible Consider satisfying the least-demanding remaining child with the smallest cookie that can work. ``` ### What a Strong Answer Covers - Sorting both requirements and cookie sizes. - Advancing past too-small cookies without discarding an unsatisfied child. - A greedy exchange argument and empty-input handling. ### Follow-up Questions - How would you return one actual assignment instead of only the count? - Why does assigning the largest cookie to the easiest child risk wasting capacity?

Overview: Maximize satisfied children by greedily assigning sorted cookie sizes, with an exchange proof, empty-input handling, and optional assignment reconstruction.

Read the full Amazon Software Engineer interview experience this question came from

Amazon logo
Amazon
Nov 10, 2026
hardSoftware EngineerOnsiteCoding & Algorithms
0
0

Each child has a minimum acceptable cookie size, and each cookie has a size. A child is satisfied by one cookie at least as large as that child's requirement. Each cookie can be assigned to at most one child. Return the maximum number of satisfied children.

Clarifying Questions to Ask Guidance

  • Can each child receive at most one cookie, and are cookie sizes indivisible?
  • May the input arrays be sorted in place?

What a Strong Answer Covers Guidance

  • Sorting both requirements and cookie sizes.
  • Advancing past too-small cookies without discarding an unsatisfied child.
  • A greedy exchange argument and empty-input handling.

Follow-up Questions Guidance

  • How would you return one actual assignment instead of only the count?
  • Why does assigning the largest cookie to the easiest child risk wasting capacity?