FastPrepImplement a FIFO Queue
Problems/Implement a FIFO Queue

Implement a FIFO Queue

Optiver logoOptiver● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Optiver intern phone screen. The report keeps the idea of building a queue by hand, the operations to implement, and the need to test it. It does not give the function signature. Our version is about 90% the same as the reported question.

Implement the behavior of a first-in, first-out queue without using a built-in queue or deque type.

Process the paired arrays operations and values from left to right:

  • push: append values[i] to the back of the queue.
  • pop: remove the value at the front and append that value to the result.
  • peek: append the value at the front to the result without removing it.

Return all values produced by pop and peek, in operation order. A push operation produces no result.

Function

queueOperations(operations: String[], values: int[]) → int[]

Examples

Example 1

operations = ["push","push","peek","pop","peek"]values = [4,7,0,0,0]return = [4,4,7]

The first peek reads 4. The following pop removes and returns 4, so the final peek reads 7.

Example 2

operations = ["push","push","pop","push","peek","pop","pop"]values = [10,20,0,30,0,0,0]return = [10,20,20,30]

After removing 10, pushing 30 leaves the queue as [20,30]. The remaining operations read and remove those values in FIFO order.

Example 3

operations = ["push","push","peek","pop","peek","pop"]values = [-2,-2,0,0,0,0]return = [-2,-2,-2,-2]

Equal and negative values retain their insertion order. A peek does not remove the front value.

Constraints

  • 1 <= operations.length == values.length <= 100000.
  • Each operation is push, pop, or peek.
  • For push, -10^9 <= values[i] <= 10^9; for other operations, values[i] is ignored.
  • Every pop or peek occurs while the queue is nonempty.
  • Do not use a built-in queue or deque type.

More Optiver interview questions

  • Multi-Level Inventory Storage SystemOA · PHONE SCREEN · Seen Aug 2026
  • Client Stock Position OperationsPHONE SCREEN · Seen Aug 2026
  • Implement TriePHONE SCREEN · Seen Aug 2025
  • 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
  • Proportional Momentum Investment StatisticsOA · Seen Aug 2026
  • Count Bounded Share TransactionsOA · Seen Aug 2026
  • Count Ordered Size SequencesOA · Seen Aug 2026

Similar questions at other companies

  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Music Player Operation SequenceAtlassian · PHONE SCREENAtlassian interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Five-Minute Hit CounterGoogle · ONSITE INTERVIEWGoogle interview questions
  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Customer Bootstrap APIDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions

Optiver interview experiences

  • Optiver SWE Intern OA: CPU Temperature Simulation: 1 Experience
  • Optiver Trading Intern Market-Making Games: 1 Experience
  • Optiver Quant Trader Intern Technical Interview: 1 Experience
  • Optiver SWE Intern System Design Interview: 15 Experiences
All Optiver interview questionsSee Optiver hiring insights
Saved
class Solution {
    public int[] queueOperations(String[] operations, int[] values) {
        // Write your code here.
    }

}
Checking account…