Unlike traditional problems dealing with push and pop sequences of distinct numbers, I would like to know the procedure to determine the validity of the stack operations for sequences of non-distinct numbers.

For example,

Push : 1 2 1 2 2 2 1

Pop : 2 2 1 2 2 1 1

is a valid operation for stack.

Any way to figure this out in n steps?

  • 1
    $\begingroup$ Could you please explain what is a valid sequence in detail? $\endgroup$ – xskxzr Oct 26 '18 at 17:16
  • $\begingroup$ Welcome to Computer Science! We discourage posts that simply state a problem out of context, and expect the community to solve it. Assuming you tried to solve it yourself and got stuck, it will be helpful if you wrote your thoughts and what you could not figure out. It will definitely draw more answers to your post. Until then, the question will be voted to be closed / downvoted. You may also want to check out these hints $\endgroup$ – John L. Oct 27 '18 at 3:55
  • $\begingroup$ Once done with the formality above, I am going to predict this question comes from a homework assignment or some kind of online exam/competition. So the user may not reveal what is this problem exactly. However, without that critical piece of information, there is no way to answer the question. Let me see if my prediction is correct or not. $\endgroup$ – John L. Oct 27 '18 at 4:01
  • $\begingroup$ Clock is ticking. In another 24 hours, I am going to vote to close this question. Hmm, who has voted up this question? $\endgroup$ – John L. Oct 27 '18 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.