1
How do you guys come up with such an algorithm
I was on an Apple QA interview yesterday, and I was asked to design a stack, which can do push and pop, and should have O(1) complexity to find the minimum value.
I couldn't solve the problem, so after the interview, I looked up Google and found this:
https://www.geeksforgeeks.org/design-a-stack-that-supports-getmin-in-o1-time-and-o1-extra-space/
I wonder how you come up with such a solution when given the problem. It seems just incredible.