04Implement an LRU cache with O(1) get and put, then make it thread-safe with TTL.▼mediumOpenAIGoogleMeta2 repliesunlockedThe single most-asked design-coding question, and a common warm-up at the labs ahead of the ML follow-ups. The signal is the hashmap-plus-doubly-linked-list for genuine 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 archetypal pointer-handling screen. What interviewers watch for: the three-pointer walk executed without ever dropping the tail of the list, plus why the iterative version wins over 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 finds a cycle in O(1) space, but what sets strong candidates apart is the second phase: a brief distance argument that identifies exactly where the loop starts. 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 have to intersect at a single node, but aligning their lengths without counting is the elegant move interviewers look for. Here is the two-pointer trick that cancels the lengths 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 asks for a single pass: a gap of N between two pointers, plus a dummy head that makes deleting the real head come out for free. Here is the clean answer.Open full answer →