Frage im Vorstellungsgespräch bei Petal

Write a constant-time Python 3 implementation of LRU cache. Use any Python data structures. The provided unit tests must pass. You have 15 minutes.

Antworten zu Vorstellungsgespräch

Anonym

20. Jän. 2019

When I attempted to solve this problem using the in-built sorted feature of the dictionary data structure in Python 3.6+, I was told that using it is not fair, that I cannot assume a dictionary to be sorted. I was mystified since just moments ago I had been told to use any Python data structure. It's as if I was being set up to fail. After my time was up, the interviewer proceeded to talk about his ideal implementation which used pointers. Did he not know that Python doesn't use pointers? He nitpicked about why my time-restricted approach wasn't DRY. Also, what does implementing an LRU cache have to do with any real-life problem that is to be solved in this time frame?

1

Anonym

10. Mai 2019

Hi I think your approach is not efficient enough. LRU could be implemented using double LinkedList and dictionary. Where Linked list manages the elements (keys) and ranks them according to the recency of the access and dictionary provides the value for the key..