04LRU cache in O(1): hashmap plus doubly linked list, TTL, locking.▼mediumOpenAIGoogleMeta2 repliesunlockedHashmap for lookup, doubly linked list for recency, move-to-front on access, evict at the tail. Then the usual follow-ups: TTL and thread safety.Open full answer →
35Reverse a linked list (iterative and recursive), and the pointer-manipulation pattern.▼easy★ EssentialGoogleMetaAmazon1 replies◆ premiumReversing a linked list is the canonical pointer-handling screen. The signal is the three-pointer walk done without ever losing the rest of the list, plus knowing why the iterative version beats recursion in production. Here is the answer.Open full answer →
81Detect a cycle in a linked list, and find where the cycle starts.▼mediumMetaAmazonMicrosoft2 replies◆ premiumFloyd's tortoise and hare detects a cycle in O(1) space, but the part that separates strong candidates is the second phase: a short distance argument that pinpoints exactly where the loop begins. Here is the answer and the math.Open full answer →
82Find the node where two singly linked lists intersect.▼mediumAmazonMicrosoftMeta1 replies◆ premiumTwo lists that share a tail must intersect at a single node, but matching their lengths without counting is the elegant move interviewers want. Here is the two-pointer trick that makes the lengths cancel out, plus the answer.Open full answer →
83Remove the Nth node from the end of a linked list in one pass.▼mediumMetaAmazonMicrosoft1 replies◆ premiumThe two-pass length-then-delete solution works, but the interview wants a single pass: a gap of N between two pointers, plus a dummy head that makes deleting the real head fall out for free. Here is the clean answer.Open full answer →