Seconds Until a Customer Collects All Items at a Pickup Counter
Last updated: November 29, 2026
Quick Overview
Customers wait in a single line at an Amazon Fresh pickup counter, and customer i needs items[i] items. Each second the front customer receives one item, then leaves if done or goes to the back of the line otherwise. Return the number of seconds until customer k has all items.
Amazon
November 29, 20260
0
0 solved
Customers wait in a single line at an Amazon Fresh pickup counter, and customer i needs items[i] items. Each second the front customer receives one item, then leaves if done or goes to the back of the line otherwise. Return the number of seconds until customer k has all items.
An Amazon online assessment problem where a queue simulation passes but the grader also rewards the O(n) counting insight. Expect a follow-up asking for the closed form.
What the Interviewer Expects
- Writes a correct queue simulation
- Derives the O(n) formula with min(items[i], items[k]) and min(items[i], items[k] - 1)
- Explains why people behind k get one fewer turn
- Handles k at the front and back of the line
- States the simulation's O(sum) cost
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
- Return the finishing time for every customer at once.
- What if each turn serves up to c items?
- What if new customers can join mid-way?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list items of positive integers and index k. Output: total seconds until customer k receives their last item. Each second serves exactly one item to the front person....
High-Level Design
A deque simulation works but costs O(sum of items). Instead count how many items each person receives before k finishes. When k gets their last item, everyone at or ahead of k (index <= k) has had min...