Question d’entretien chez Google

Question: Designed an efficient key-value data structure, each element has an elapsed time. For example, elements A with elapsed time 15 (keyA , (valueA , 15)) will be removed from the data structure after 15 seconds from the time it was added to the data structure

Réponse à la question d'entretien

Utilisateur anonyme

4 sept. 2018

Two hash maps? One for the deadlines with key the time references and value an array of the elements keys corresponding to that deadline and another for actually getting the elements. So get, update and deletion are O(1). Actually when you meet a deadline, it's O(|elements in that deadline|), which I believe cannot be smaller.