Domanda di colloquio di Microsoft

Given a Stack with n elements, write a method that always keeps the max of the stack?

Risposta di colloquio

Anonimo

26 feb 2015

Every data structure you may think of for say linked list or an array list etc.. gives us an O(n) runtime but if we create another stack and only push when a higher element comes in then that enables us to have O(1) runtime.

2