Question d’entretien chez Google

Design a data structure for LRU cache

Réponses aux questions d'entretien

Utilisateur anonyme

25 juill. 2009

Would a Priority Queue work here? If we have a hash function to help us the lookup, then we might have to just end up truncating tail of the Queue and add element to the head or vice versa.

Utilisateur anonyme

14 juill. 2018

In java, just extend the LinkedHashMap static class MyLru extends LinkedHashMap { int capacity; public MyLru(int capacity){ super(capacity,0.75f,true); this.capacity = capacity; } @Override protected boolean removeEldestEntry(Map.Entry eldest) { if(size()>capacity) { return true; } return false; } }

Utilisateur anonyme

19 mars 2009

There are many ways to do this

1