We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Thiiiis feels like a poorly-designed problem. In addition to the lack of polymorphism mentioned in the top voted comment, the question presents the cache as a way to avoid doing expensive lookups, which, okay, a linked list is expensive to sort through. But then, it provides you a std::map mp, which lets you look up nodes quickly anyways?
std::map can't be used for implementing LRU as-is since it doesn't store any information about recency, unless I'm missing something? It's not clear from the description, either:
"mp - Map the key to the node in the linked list"
That's a request, not a description.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Abstract Classes - Polymorphism
You are viewing a single comment's thread. Return to all comments →
Thiiiis feels like a poorly-designed problem. In addition to the lack of polymorphism mentioned in the top voted comment, the question presents the cache as a way to avoid doing expensive lookups, which, okay, a linked list is expensive to sort through. But then, it provides you a std::map mp, which lets you look up nodes quickly anyways?
std::map can't be used for implementing LRU as-is since it doesn't store any information about recency, unless I'm missing something? It's not clear from the description, either:
"mp - Map the key to the node in the linked list"
That's a request, not a description.