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.
Use two queues to simulate stack operations efficiently.
Maintain the top element in one of the queues for easy acces...read more
Help your peers!
Add answer anonymously...
JPMorgan Chase & Co. Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Count Subarrays with Given XOR Problem Statement You are given an array of integ...read more
A Software Developer Intern was asked Q. Kth Largest Number Problem Statement You are given a continuous stream of number...read more
A Software Developer Intern was asked Q. Stack using Two Queues Problem Statement Develop a Stack Data Structure to store...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Count Subarrays with Given XOR Problem Statement You are given an array of integ...read more
A Software Developer Intern was asked Q2. Kth Largest Number Problem Statement You are given a continuous stream of number...read more
A Software Developer Intern was asked Q3. Stack using Two Queues Problem Statement Develop a Stack Data Structure to store...read more
>
JPMorgan Chase & Co. Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

