Given a continuous stream of integers and two stacks. I want to implement extractMin operation which runs in O(1) complexity. This operation pops out minimum element from record and returns it. Basic solution is to keep the data in reverse sorted order using 2 stacks. This way we can simply pop out the top element of stack containing data. But with this, insertion is O(N) for every integer. Can I get better complexity in insertion, keeping the extractMin operation to be O(1).
Adding example to make it more clear:
10,-20,2,-3,-5,10,20 (integer stream at any moment).
extractMin() // returns -20
extractMin() // returns -5