Earliest Day to Assemble M Gift Sets From Adjacent Ready Items
Last updated: November 29, 2026
Quick Overview
Item i on a packing line becomes ready on day ready[i]. A gift set needs k adjacent ready items, and each item can belong to only one set. Return the earliest day on which m gift sets can be made, or -1 if impossible.
Amazon
November 29, 20260
0
0 solved
Item i on a packing line becomes ready on day ready[i]. A gift set needs k adjacent ready items, and each item can belong to only one set. Return the earliest day on which m gift sets can be made, or -1 if impossible.
An Amazon technical screen question applying binary search to time. It resembles holiday gift-set kitting where only contiguous items on a line can be bundled; the interviewer checks the greedy counting inside the check and the early impossibility test.
What the Interviewer Expects
- Return -1 immediately if m * k exceeds the number of items
- Search over days between min and max ready day
- Greedily count contiguous ready runs, cutting a set every k items
- Explain why the count is monotonic in the day
- Give O(n log D) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Can you search over the sorted distinct ready days instead of the integer range?
- What if sets could use any k ready items, not just adjacent ones?
- How would you report which sets to make?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: list ready of n positive integers, integers m and k. Output: smallest day d such that, treating items with ready[i] <= d as available, you can form m disjoint runs of k consecutive available i...
High-Level Design
If m * k > n, no day works. Otherwise the latest ready day makes every item available, so an answer exists in [min(ready), max(ready)]. For a candidate day, scan the line counting consecutive availabl...