Connecteam Interview Question

Implement (actually explain, because it's over the phone), a "max()" function inside of a Stack data structure of numbers. Meaning that every time you'll do a push() or poll() actions, you can run max() and say what is the current max number in the stack. This has to be an O(1) of time complexity and he don't care about space complexity.

Interview Answer

Anonymous

May 7, 2023

Just manage another maxStack structure and push always the current max depending on the coming numbers of the general stack.