When asking to implement LRU cache in a phone interview/virtual onsite, do you expect the interviewee to implement the doubly LinkedIn list from scratch and use it in the LRU implementation or is it ok to use something like an ordered dict that is implemented using DLL behind the scenes.
I think the list implementation in python is doubly LinkedIn list so use that with a hash set maybe
Set? If the existing element appears again, how would we place on the end? Just Curious..
A hash set in Python requires that the element implement the __hash__ function, so if someone uses a set over a dict for whatever reason, they'd need to implement that function on their DoublyLinkedList impl or say that they would.
Sometimes interviewers are not aware of ordereddict/linkedhashmap, ask them before coding. Sometimes they will say no, because it gives away the underlying concept of combining two datastructures.
When they asked you this, they expect you to implement from scratch, otherwise, just use the one line built in lru cache
A doubly linked list in Python is like a 6 line class. For anyone more senior than a new grad, I would expect a small doubly linked list implementation and use a standard dict. They could use OrderedDict if they briefly describe how they would implement it without an OrderedDict or if they bring up that they're in a modern version of Python and dicts are ordered by default.
from sickalgos.leetcode import lrucache
Cars
Yesterday
1682
Electric cars depreciate 10 times faster than gasoline cars
Personal Finance
Yesterday
2826
Should I marry a lazy girl?
AMA
Yesterday
1272
I have worked at TikTok US core tech for 3 years. AMA.
Tech Industry
Yesterday
1840
I do tech screens at Google. AMA
India
Yesterday
1044
What do vegetarian Indians eat for protein?
Ask the interviewer. There is no correct answer.