Stack using Two Queues Problem Statement

Develop a Stack Data Structure to store integer values using two Queues internally.

Your stack implementation should provide these public functions:

Explanation:

1. Constructor: Initializes the two queue data members. 2. push(data): Accepts an integer and pushes it onto the stack. 3. pop(): Removes and returns the top element in the stack; returns -1 if empty. 4. top: Returns the top element without removing it; returns -1 if empty. 5. size(): Returns the current number of elements in the stack. 6. isEmpty(): Checks if the stack is empty and returns a boolean result. 

Input:

The first line contains an integer 'Q', representing the number of queries. The next 'Q' lines specify each operation: - For push, the line contains two integers: the operation type and the integer value to push. - For other operations, the line consists of a single integer indicating the operation type.

Output:

- For Query-1, do not return anything. - For Query-2, output the popped value. - For Query-3, output the current top value. - For Query-4, output the size of the stack. - For Query-5, output 'true' or 'false'. Each query's output should be on a different line.

Example:

Input:
Q = 5 1 42 2 3 1 17
Output:
42 -1 17

Constraints:

  • 1 <= Q <= 1000
  • 1 <= query type <= 5
  • -10^9 <= data <= 10^9 and data ≠ -1
Note:
Direct output printing is handled externally. Focus on implementing the stack functionality.
AnswerBot
4mo

Implement a stack using two queues to store integer values with specified functions.

  • Create a stack class with two queue data members.

  • Implement push, pop, top, size, and isEmpty functions.

  • Ensure proper...read more

Help your peers!
Select
Add answer anonymously...

Top Software Quality Engineer Interview Questions Asked at Adobe

Q. Leaders in an Array Problem Statement You are given a sequence of numbers. Your ...read more
Q. Spiral Matrix Path Problem You are provided with a two-dimensional array named M...read more
Q. Find the Second Largest Element Given an array or list of integers 'ARR', identi...read more
Software Quality Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits