msito
BAN USER
Questions (5)
Comments (1)
Reputation 190
- 3of 3 votes
AnswersImplement a stack with O(1) push, pop, and min
- msito in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Stacks - 0of 2 votes
AnswersImplement a LRU cache with O(1) addCache and removeCache.
- msito in United States| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Cache - 0of 0 votes
AnswersWhat is a HashMap? What is one advantage of using a HashMap versus a TreeMap?
- msito in United States| Report Duplicate | Flag | PURGE
Amazon Intern Java
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
A few people missed this -- when testing if the value currently being pushed onto the stack is less than the minimum, you should also test if it is equal to the current minimum. This will cause you to have duplicates in your min stack, but if you think about it this is exactly what you want if you push duplicate minimum values in your original stack.
- msito October 15, 2013Try your solution with alternating equivalent minimums eg. 1 3 1 4 1 5
Stack: 5->1->4->1->3->1
Min stack: 1->1->1
This way, if the value you're currently popping is equal to the current min, you just pop the min from the min stack as well.