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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

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
queue simulation
counting
round robin
math shortcut
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported