Implement Stack Using Two Queues
Updated
Problem statement
Given a list of operations, run them on a last-in-first-out stack that you build from exactly two FIFO (first-in-first-out) queues. Return one string per command.
push x: push x onto the stack and output"null".pop: remove the top integer and output it.top: output the top integer without removing it.empty: output"true"if the stack is empty, otherwise"false".
Make push and top run in O(1) time.
Function
processStackUsingQueues(operations: String[]) → String[]Examples
Example 1
operations = ["push 1","push 2","top","pop","empty"]return = ["null","null","2","2","false"]Two was pushed last, so top and pop both output it. One value is still in the stack, so empty outputs false.
Constraints
1 <= operations.length <= 10^4.- Pop and top are called only on a nonempty stack.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Implement a Queue Using Two StacksOracle · PHONE SCREENOracle interview questions
- Build a Queue From Two StacksAdobe · PHONE SCREENAdobe interview questions
- 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
- Rolling Hit CounterDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
- Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
- Per-Client API Rate LimiterDocker · PHONE SCREEN
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
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)