title: Implementation Removing adjacent numbers of a stack, how many remaining?
body: <p>Assume we have a stack with <code>n</code> numbers and if 3 or more adjacent numbers are equal then these numbers can be removed (the numbers are removed from top to bottom). Since this is a stack we have the normal <code>push()</code>, <code>pop()</code>, <code>top()</code> operations and we know <code>n</code>. Moreover I have an empty stack and <code>O(1)</code> extra memory space. Is there a linear algorithm for finding the quantity of the remaining number? If yes, what would that be?</p>