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?