3 ms·
Make another stack with the latest minimum, then when you pop that top value, you also pop it off the minimums stack. Then you have the last minimum before that
by wadeboggs 10y ago
Make another stack with the latest minimum, then when you pop that top value, you also pop it off the minimums stack. Then you have the last minimum before that one.
Is that it?
- sand500 10y agoWhat if you added values that are greater then the minimum at the top of the minimum stack but less than the next value on the minimum stack?
- antoaravinth 10y agoYour using two stacks now. This is the solution that I had told but your not satisfying the condition w.r.t to space , its O(n) not O(1).