FastPrepCustomer Checkout Duration
Problems/Customer Checkout Duration

Customer Checkout Duration

Optiver logoOptiver● MediumINTERNNEW GRADOA

Updated Oct 2026

QuestionFunctionExamples

Problem statement

A supermarket has several checkout lines. Each customer joins one line and cannot switch lines before leaving. Process the instruction stream and return customer IDs in the order in which they leave the supermarket.

Priority rules

  • A customer leaves as soon as all of their items have been processed.
  • If a customer increases their total item count, move them to the back of the same line.
  • If a customer decreases their total item count, keep their position. If the new total is no greater than the number of items already processed, they leave immediately.
  • When one operation makes customers from several lines leave simultaneously, customers from smaller line IDs leave first.

Instructions

  • CustomerEnter customerId lineNumber numItems: add a new customer to the back of the specified line.
  • BasketChange customerId newNumItems: replace the customer's total item count with newNumItems. Previously processed items remain processed.
  • LineService lineNumber numProcessedItems: process that many items from the front of one line. Any unused processing continues with the next customer in that line.
  • LinesService: simultaneously process one item from the front customer of every non-empty line.

Complete customerCheckout(String[] instructions) and return an array containing every departing customer ID in departure order.

Function

customerCheckout(instructions: String[]) → int[]

Examples

Example 1

instructions = ["CustomerEnter 123 1 5", "CustomerEnter 3 1 2", "LineService 1 4", "BasketChange 123 6", "LineService 1 5"]return = [3, 123]

Upon first LineService 4 out of 5 items of customer 123 are processed. However, customer then increases the number of items in their basket (namely adds 1 extra item), this puts them at the back of the line.

During the next LineService call customer 3 is checked out first, and customer 123 is checked out next (as they only had 2 items left to process).

More Optiver interview questions

  • Overheat Prevention ControllerOA · Seen Nov 2026
  • Power Cell BankOA · Seen Nov 2026
  • Count Straight-Line Word Occurrences in a GridOA · Seen Sep 2026
  • Fastest Average Speed over a Rolling KilometerOA · Seen Sep 2026
  • Multi-Level Inventory Storage SystemOA · PHONE SCREEN · Seen Aug 2026
  • Proportional Momentum Investment StatisticsOA · Seen Aug 2026
  • Count Bounded Share TransactionsOA · Seen Aug 2026
  • Count Ordered Size SequencesOA · Seen Aug 2026
  • Profitable Currency Exchange CycleOA · Seen Aug 2026
  • Client Stock Position OperationsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Per-Client Sliding-Window Rate LimiterGeneral Motors · OA
  • Priority Message BufferAmazon · ONSITE INTERVIEW
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • VIP and Regular Service SchedulerIntuit · PHONE SCREEN
  • Five-Minute Hit CounterGoogle · ONSITE INTERVIEW
  • Implement a FIFO QueueByteDance · PHONE SCREEN
  • Stateful Paginated Fetch NLyft · PHONE SCREEN
  • Music Player Operation SequenceAtlassian · PHONE SCREEN
  • Ring Buffer OperationsApplied Intuition · PHONE SCREEN
  • Recent Event Stream QueriesSnowflake · PHONE SCREEN
See Optiver hiring insights
Saved
class Solution {
    public int[] customerCheckout(String[] instructions) {
      // write your code here
    }

}
Checking account…