Challenge: Implement Queue Using Stack
Can you implement a queue using a built-in stack? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.
We'll cover the following
Problem Statement #
In this problem, you have to implement enqueue()
and dequeue()
, and use a built-in Stack to insert or remove value to and from the queue. An illustration is also provided for your understanding.
Method Prototype #
void enqueue(int value)
int dequeue()
Input/Output #
-
enqueue()
Input: an integer
Output: returns true after inserting value in the queue
-
dequeue()
Input: an integer
Output: returns true after removing value from the queue
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.