Assign Cookies to Maximize Satisfied Children
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Onsite
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
Constraints
- requirements and cookies may each contain 0 through 2^31 - 1 entries.
- Every requirement and cookie size is an integer from 0 to 2^53 - 1, inclusive.
Examples
Input: ([4, 1, 7], [1, 7, 3])
Expected Output: 2
Explanation: Give sizes 1 and 7 to children who require 1 and 7. The size 3 cookie cannot satisfy the child who requires 4.
Input: ([2, 5], [5, 2])
Expected Output: 2
Explanation: Giving each child a cookie exactly at its requirement satisfies both.
Hints
- If a cookie is too small for one child, identify which other children it can still satisfy.