Question: Given a stack which can keep M numbers at most, write a new function for this stack class. Push N numbers and pop randomly. The

 Given a stack which can keep M numbers at most, write

Given a stack which can keep M numbers at most, write a new function for this stack class. Push N numbers and pop randomly. The new function should tell if a given sequence of numbers is a possible pop sequence of a given input push sequence. Sample input: ("1,2,3,4,5", "4,5,3,2,1") should return: Yes, because you can push 1,2,3,4 and pop 4, and push 5, then pop 5,3,2,1. Note: "1,2,3,4,5" is the input push sequence, "4,5,3,2,1" is one possible pop sequence. "Given a stack" means you can assume you have a stack class with common attributes and functions implemented. Another sample input: ("1,2,3,4,5", "4,3,5,1,2") should return: No 1) write the new function 2) what's the big-O of your function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!