04Implement an LRU cache with O(1) get and put, then make it thread-safe with TTL.▼mediumOpenAIGoogleMeta2 repliesunlockedThe most-asked design-coding question, and a frequent warm-up at the labs before the ML follow-ups. The signal is the hashmap-plus-doubly-linked-list for true O(1), then handling the TTL and concurrency follow-ups cleanly. Here is that build.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 →