TripAdvisor

www.tripadvisor.com

Interview Question

Software Engineer Interview Newton, MA

How would you implement an LRU Cache (LRU - Least Recently

  Used). What would your data structure look like. This was also a whiteboard problem.
Answer

Interview Answer

2 Answers

0

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

Interview Candidate on Apr 27, 2012
0

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.

anonymous on Aug 17, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.