0% found this document useful (0 votes)
107 views1 page

Stacks and Queue Assignment

The document outlines 6 stack and queue problems: (1) Implement a queue with two stacks making enqueue and dequeue efficient. (2) Implement a stack with two queues making push and pop efficient. (3) Reverse a queue using recursion. (4) Check for duplicate parentheses in an expression. (5) Implement a min stack class using two stacks that supports efficient push, pop, and getting the minimum element. (6) Calculate stock span using a stack to do it in linear time, or an array approach in quadratic time.

Uploaded by

Himanshu Gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views1 page

Stacks and Queue Assignment

The document outlines 6 stack and queue problems: (1) Implement a queue with two stacks making enqueue and dequeue efficient. (2) Implement a stack with two queues making push and pop efficient. (3) Reverse a queue using recursion. (4) Check for duplicate parentheses in an expression. (5) Implement a min stack class using two stacks that supports efficient push, pop, and getting the minimum element. (6) Calculate stock span using a stack to do it in linear time, or an array approach in quadratic time.

Uploaded by

Himanshu Gautam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

                               

 
Crux Assignment  (Stack and Queue)     
 
1. Implement a Queue using two stacks 
a. Make Enqueue efficient 
b. Make Dequeue efficient 
2. Implement a Stack using two queues 
a. Make push efficient 
b. Make pop efficient 
3. Reverse a Queue using recursion 
4. Check for duplicate parenthesis in an expression e.g. ((a + b) + ((c+d))) has duplicate 
parenthesis  
5. Implement a class MinStack using the stack class we have already built. It should 
support O(1) push, O(1) pop and O(1) getMinimum() functions where getMinimum() 
returns the minimum element present in the stack. (Hint: You would need two stacks for 
doing this) 
6. The span si of a stock’s price on a certain day i is the maximum number of consecutive 
days (up to the current day) the price of the stock has been less than or equal to its price 
on day i. Given input array with all stock prices return the spans. We can do this using an 
array in O(n^2) time but stack can help us do it in O(n) time. Implement the array 
approach if you can’t find a solution using stack.  

You might also like