Pergunta de entrevista da empresa Tripadvisor

How would you implement an LRU Cache (LRU - Least Recently Used). What would your data structure look like. This was also a whiteboard problem.

Respostas da entrevista

Sigiloso

27 de abr. de 2012

The answer is to use a LinkedHashMap or a similar data structure because it allows O(1) on all needed operations.

Sigiloso

17 de ago. de 2012

LinkedHashMap works only if an item is used only once, so you need to implement your own O(1) insertion, deletion and search that are tailored to LRU.