Loading…
Loading…
get(key) and put(key, value) must both run in O(1).get and put count as "using" a key (move it to most-recently-used).A hash map alone gives O(1) lookup but no ordering. A linked list alone gives ordering but O(n) lookup. What single data structure combination gives you both — O(1) lookup and O(1) reordering?
Design your own solution first — on paper, a whiteboard, or your own IDE — before checking the reference.