two stacks O(n)