Implement Queue Using Stacks
Updated
Problem statement
Implement a first-in-first-out queue using only two stacks. The queue supports push, pop, peek, and empty.
The function receives parallel arrays operations and arguments. Process them in order. MyQueue creates the queue, push uses the first integer in the corresponding argument array, and the remaining operations take no arguments.
Return one string for every operation: null for MyQueue and push, the returned integer for pop and peek, and true or false for empty.
Use only standard stack operations: push to the top, read or remove the top, size, and emptiness checks.
Function
MyQueue(operations: String[], arguments: int[][]) → String[]Examples
Example 1
operations = ["MyQueue","push","push","peek","pop","empty"]arguments = [[],[1],[2],[],[],[]]return = ["null","null","null","1","1","false"]Create the queue, push 1 and 2, then peek and pop the front value 1. One value remains, so empty returns false.
Constraints
1 <= x <= 9- At most 100 calls will be made to push, pop, peek, and empty.
- All the calls to pop and peek are valid.
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
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
- 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
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)