
You are given the head of a singly linked list where each node has:
next
: pointer to the next node
random
: pointer to any node in the list or
null
Return a deep copy of the list (all new nodes), preserving both next and random relationships.
Goal: The copied list must not share any nodes with the original.
Design a data structure LRUCache that supports:
get(key)
: return the value for
key
if present, else
-1
put(key, value)
: insert or update the value
The cache has a fixed capacity C. When inserting causes the cache to exceed C, it must evict the least recently used item.
get
and
put