Google Interview Question
1,069 Interview Reviews |
Back to all Google Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Senior Software Engineer at Google:
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (4)
Since you're only interested in the N most recently accessed items, an array is suffice. Because N is essentially the index right?
Helpful Answer?
Yes |
No
Inappropriate?
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.
Helpful Answer?
Yes |
No
Inappropriate?
http://stackoverflow.com/questions/1935777/c-design-how-to-cache-most-recent-used
Helpful Answer?
Yes |
No
Inappropriate?
Members can
answer or comment on this question
–
Join Now (It's Free) or
Sign In
0 of 0 people found this helpful
by Interview Candidate: