MockQuestions

Google Software Developer Mock Interview

Question 3 of 30 for our Google Software Developer Mock Interview

Get More Information About Our Google Interview Questions

Question 3 of 30

How do you approach implementing an LRU Cache in your favorite programming language?

"The way I approach implementing an LRU Cache is based on what programming language is used in the development environment. Yes, I do have a preference, but I consider it a tool in a toolbox; I use whatever is available to me to easily adapt my process to the ones used here at Google. Java seems to be a tool of choice in most development environments, and for me as well. Say, for example, we are given total possible page numbers that can be referred. We are also given cache (or memory) size (number of page frames that the cache can hold at a given time). The LRU caching scheme is intended to remove the least recently used frame when the cache is full, and thus a new page is referenced which was not in the cache before. Examples of this approach and method are referenced in the Galvin book."

Next Question

How to Answer: How do you approach implementing an LRU Cache in your favorite programming language?

Advice and answer examples written specifically for a Google job interview.

  • 3. How do you approach implementing an LRU Cache in your favorite programming language?

      How to Answer

      Having a favorite programming language tells a lot about the experience and expertise level of a software developer. There are numerous languages to pick from, and depending on what applications you are working on and what you intend to achieve, some might work better than others. The Google hiring manager might start with a question about your favorite language and then move to your approach and possibly your methodology or reasoning for favoring that language. Let me give an example of how this question might be answered. If we intend to use Java for this example, we would look at the LRU cache and recently used entries, then remove the element from the bottom and add an element to the start of a LinkedList. Wherever any entry is accessed, it is moved to the top so that recently used entries will reside at the top, and the least used entries will reside on the bottom.

      Answer Example

      "The way I approach implementing an LRU Cache is based on what programming language is used in the development environment. Yes, I do have a preference, but I consider it a tool in a toolbox; I use whatever is available to me to easily adapt my process to the ones used here at Google. Java seems to be a tool of choice in most development environments, and for me as well. Say, for example, we are given total possible page numbers that can be referred. We are also given cache (or memory) size (number of page frames that the cache can hold at a given time). The LRU caching scheme is intended to remove the least recently used frame when the cache is full, and thus a new page is referenced which was not in the cache before. Examples of this approach and method are referenced in the Galvin book."