Pergunta de entrevista da empresa Google

Create a cache with fast look up that only stores the N most recently accessed items.

Respostas da entrevista

Sigiloso

14 de jul. de 2009

Use a hash map and a queue.

2

Sigiloso

19 de jul. de 2009

To ml: N was not the index, instead some random key. The combined data structure had the implement the interface: Object get(String key); and void put (String key, Object obj); Besides the array isn't the best choice when you have to take an object out of the array and add it to the front of the queue every time the object is accessed. A double linked list works better. The hash map entries points to an item in the linked list, which then points to the object to be returned. This way you can find the item quickly to move it to the front of the queue.

Sigiloso

21 de ago. de 2010

This answer below has the best solution: http://stackoverflow.com/questions/1935777/c-design-how-to-cache-most-recent-used

1

Sigiloso

18 de jul. de 2009

I think you can do better than hash map and a queue...or just simply it. Since you're only interested in the N most recently accessed items, an array is suffice. Because N is essentially the index right?