FastPrepRun a Queue Built From Stacks
Problems/Run a Queue Built From Stacks

Run a Queue Built From Stacks

Capital One logoCapital One● EasyINTERNFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two Capital One reports raise the idea of a queue made out of stacks. One is from an intern in January 2017 and one is from February 2016. One of them allows several stacks.

The reports specify no operations or limits. This version feeds the queue a list of commands (enqueue, dequeue, front, size) and collects one number per reading command. The number is -1 whenever nobody is waiting. Outputs cannot reveal what the queue is made of, so the construction lives in the editorial. These are our choices.

Our version is about 70% the same as the reported questions.

A line of customers starts empty, and people are served in the order they arrived. Process commands from first to last; commands[i] is one of:

  • "enqueue": a new customer numbered values[i] joins the back of the line.
  • "dequeue": the customer at the head of the line is served and leaves; record their number. If nobody waits, record -1.
  • "front": record the number of the customer at the head without serving them, or -1 when nobody waits.
  • "size": record how many customers are waiting.

Entries of values that sit beside a command other than "enqueue" are 0 and carry no meaning. The answer is every number you recorded, first to last. The line is meant to be built from two stacks and nothing else.

Function

runQueue(commands: String[], values: int[]) → int[]

Examples

Example 1

commands = ["enqueue","enqueue","enqueue","dequeue","enqueue","front","size","dequeue","dequeue","dequeue"]values = [6,2,9,0,4,0,0,0,0,0]return = [6,2,3,2,9,4]

The queue serves in arrival order. After 6, 2, 9 arrive, dequeue gives 6. Then 4 arrives at the back, front is 2 and size is 3. The last three dequeues give 2, 9 and 4.

Example 2

commands = ["enqueue","dequeue","dequeue","front","size"]values = [5,0,0,0,0]return = [5,-1,-1,0]

The one customer is served, so the second dequeue finds nobody and records -1, and so does front; afterwards the line has 0 people.

Example 3

commands = ["enqueue","front","enqueue","front"]values = [8,0,3,0]return = [8,8]

The front stays 8 after 3 joins the queue, because 3 stands behind it.

Constraints

  • commands holds between 1 and 3000 entries.
  • values has as many entries as commands.
  • Each command is "enqueue", "dequeue", "front" or "size".
  • Every value is between 0 and 10^5; it is 0 for every command except "enqueue".

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Implement a Queue Using Two StacksAmazon · ONSITE INTERVIEW
  • Implement Queue Using StacksMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Stack from Queues and Queue from StacksBank of America · ONSITE INTERVIEWBank of America interview questions
  • Implement Queue Using StacksBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Implement a Queue Using Two StacksOracle · PHONE SCREENOracle interview questions
  • Build a Queue From Two StacksAdobe · PHONE SCREENAdobe interview questions
  • Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Command Undo Data StructureNetflix · ONSITE INTERVIEWNetflix interview questions
  • A Queue Built From Two StacksExpedia · ONSITE INTERVIEWExpedia interview questions
  • Implement a Basic StackAMD · ONSITE INTERVIEWAMD interview questions

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int[] runQueue(String[] commands, int[] values) {
        // Write your code here.
    }
}
Checking account…