FastPrepStack from Queues and Queue from Stacks
Problems/Stack from Queues and Queue from Stacks

Stack from Queues and Queue from Stacks

Bank of America logoBank of America● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported by a Bank of America new grad from a 2021 campus drive, in the third and last round, a one-hour technical and managerial interview. The candidate had to explain how to build a stack out of queues and a queue out of stacks, by describing it out loud rather than writing code.

The report does not list the operations. Here, you get the calls as a list of operations on both structures (push, pop, top or peek, and empty), with up to 2,000 operations, and you write working code for both.

Our version is about 75% the same as the reported question.

Build two separate structures and run a list of operations on them:

  • a stack (last in, first out) that keeps its values only in queues, and
  • a queue (first in, first out) that keeps its values only in stacks.

Inside the stack, use only normal queue operations: add to the back, remove from the front, look at the front, size and is-empty. Inside the queue, use only normal stack operations: push on top, pop from the top, look at the top, size and is-empty.

Each string in operations is one of the following:

  • "stack push x": push the integer x onto the stack.
  • "stack pop": remove the top value of the stack and output it.
  • "stack top": output the top value of the stack without removing it.
  • "stack empty": output "true" if the stack holds no values, otherwise "false".
  • "queue push x": add the integer x to the back of the queue.
  • "queue pop": remove the front value of the queue and output it.
  • "queue peek": output the front value of the queue without removing it.
  • "queue empty": output "true" if the queue holds no values, otherwise "false".

Push operations output nothing. Return the outputs of all the other operations as strings, in the order the operations run. An operation on one structure never changes the other one.

Function

runOperations(operations: String[]) → String[]

Examples

Example 1

operations = ["stack push 4","stack push 9","queue push 4","queue push 9","stack top","queue peek","stack pop","queue pop","stack empty","queue empty"]return = ["9","4","9","4","false","false"]

Both structures get 4 and then 9. The stack gives back the value pushed last, so stack top and stack pop output 9. The queue gives back the value added first, so queue peek and queue pop output 4. Each structure still holds one value, so both empty checks output "false".

Example 2

operations = ["queue push 3","queue push 5","queue pop","queue push 7","queue pop","queue pop","queue empty"]return = ["3","5","7","true"]

Values leave the queue in the order they arrived: 3, then 5, then 7, even though 7 was added after the first pop. After that the queue is empty.

Example 3

operations = ["stack push -2","stack pop","stack empty","stack push 6","stack push 1","stack top"]return = ["-2","true","1"]

The stack pops -2 and is then empty. After 6 and 1 are pushed, 1 is on top.

Constraints

  • 1 <= operations.length <= 2000
  • Each operation is one of the eight forms above, with single spaces between its words.
  • In a push, x is an integer with -10^4 <= x <= 10^4.
  • stack pop and stack top run only when the stack is not empty, and queue pop and queue peek run only when the queue is not empty.

More Bank of America Onsite Interview questions

  • Centered Star PyramidONSITE INTERVIEW · Seen Nov 2025
  • Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
  • N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
  • Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
  • Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
  • Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
  • Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
  • Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
  • Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023

Similar questions at other companies

  • Implement a Queue Using Two StacksAmazon · ONSITE INTERVIEW
  • Implement Queue Using StacksMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Implement Queue Using StacksBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Run a Queue Built From StacksCapital One · ONSITE INTERVIEWCapital One 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

Bank of America interview experiences

  • Bank of America interviews · December 2025
  • Bank of America OA · December 2025
  • Bank of America interviews · September 2026
  • Bank of America OA · September 2026
All Bank of America interview questionsSee Bank of America hiring insights
Saved
class Solution {
    public String[] runOperations(String[] operations) {
        // write your code here
    }
}
Checking account…