In this article
The basics: what a linked list is and what it costs
What is a linked list, and how is it different from an array?
A linked list is a chain of nodes, where each node holds a value and a reference to the next node, so the elements need not sit next to each other in memory. An array keeps elements side by side, which gives direct access by index. A list makes insertion or removal cheap once you hold the right node, but reaching the i-th element means walking from the head. The wider method for these rounds is in the coding interview guide.
Why it is asked: it checks that you know what each structure is good at. Source: Oracle, Java Standard Edition (SE) 17 LinkedList.
What is the difference between a singly and a doubly linked list?
In a singly linked list each node points only forward, so you move toward the tail and need the previous node to delete one. In a doubly linked list each node also points back, so a node you hold can be unlinked directly and you can walk either way, at the cost of a second reference per node. Java's LinkedList is a doubly linked list (Oracle, Java SE 17 docs, accessed October 2026).
Why it is asked: deletion and traversal costs follow from the pointer layout. Source: Oracle, Java SE 17 LinkedList.
Does Python have a built-in linked list?
Python has no built-in linked list; the closest is collections.deque, documented with approximately O(1) appends and pops at either end (Python documentation, accessed October 2026). CPython builds it as a doubly linked list of fixed-size blocks, because a comment in the 3.7.3 source says textbook lists "store one datum per link, but that gives them a 200% memory overhead" (CPython source, version 3.7.3). In an interview you write your own Node class.
Why it is asked: it separates a real data structure from a library name. Read the full explanation: Python interview questions and answers.
Is Java's LinkedList good for get(index)?
Java's LinkedList is a poor choice for get(index) because it walks from the nearer end, so the cost is still linear. The class implements both List and Deque, and its documentation says indexed operations traverse the list from the beginning or the end, whichever is closer to the index (Oracle, accessed October 2026). With 1,000 nodes (illustrative), index 900 costs 99 hops from the tail instead of 900 from the head, but that is still a walk, not a direct jump.1
Why it is asked: it tests whether you assume a list gives random access. Source: Oracle, Java SE 17 LinkedList.
Is inserting into a linked list always O(1)?
Insertion into a linked list is not always O(1): it is constant time only when you already hold the node before the insertion point, or when you insert at the head, or at the tail with a tail pointer. Finding the position by value or index is O(n) because you must walk the chain. Say both parts of the cost: the relinking is cheap, the search is not.
Why it is asked: it tests whether you state costs precisely. Read the full explanation: Coding interview questions: the patterns and the method.
Reversal questions
How do you reverse a singly linked list?
You reverse a singly linked list iteratively with a previous pointer, a current pointer and a saved next node, in O(n) time and O(1) extra space. Each loop step saves the next node, points the current node backwards and moves both pointers forward; when the current pointer is null, the previous pointer is the new head. [1,2,3,4,5] takes five flips and becomes [5,4,3,2,1].1 LeetCode 206 allows 0 to 5,000 nodes (LeetCode 206, accessed October 2026).
Text description of the diagram
- Each loop step saves the next node, points the current node backwards, then moves both pointers forward.
- When the current pointer is null, the previous pointer is the new head.
Why it is asked: it is the base move of most pointer questions. Source: LeetCode 206, Reverse Linked List.
How do you reverse a linked list recursively, and what does it cost?
You reverse a linked list recursively by reversing the part after the head, then making the second node point back at the head and setting the head's own next pointer to null; the call returns the head of the reversed rest. The problem's follow-up asks for both the iterative and the recursive version (LeetCode 206, accessed October 2026). Time is O(n), but the call stack grows with the list, so space is O(n), and a very long list can hit a language's recursion limit.
Why it is asked: it checks whether you can name the stack cost of recursion. Source: LeetCode 206, Reverse Linked List.
How do you reverse part of a linked list between two positions?
You reverse part of a linked list by walking to the node just before position left, then repeatedly moving the node after the current one to the front of the section. A dummy node is an extra node placed before the head so that changing the head needs no special case. LeetCode 92 gives head [1,2,3,4,5], left 2 and right 4, and expects [1,4,3,2,5]; that takes two moves, right minus left (LeetCode 92, accessed October 2026).1 A Salesforce candidate reported this as a fromIndex-to-toIndex question.
Why it is asked: it tests reversal with boundaries. Source: LeetCode 92, Reverse Linked List II.
How do you reverse a linked list in groups of k?
You reverse a linked list in groups of k by counting k nodes ahead and stopping if fewer remain; otherwise reverse that group with the loop above, join the previous group's tail to the new group head, and join the old group head to what follows. With [1,2,3,4,5,6,7,8] and k of 3 the result is [3,2,1,6,5,4,7,8]; the last two nodes stay in place.1 This common variant leaves a short final group unchanged, so confirm it with the interviewer. Candidates reported it for Amazon and NVIDIA loops.
Why it is asked: it combines reversal, counting and reconnecting. Read the full explanation: Coding interview questions: the patterns and the method.
How do you swap nodes in a linked list in pairs?
You swap nodes in pairs by treating it as the case where k is 2: use a dummy node, and for each pair rewire three pointers: the previous node to the second, the second to the first, the first to the node after the pair. [1,2,3,4] becomes [2,1,4,3], and an odd list such as [1,2,3] becomes [2,1,3].1 One candidate report asks for pairs first and then the generalisation to groups, so write the pair code so it extends.
Why it is asked: it checks careful pointer order, where one wrong line loses the tail. Read the full explanation: Coding interview questions: the patterns and the method.
Knowing it is half the job. Saying it is the other half.
Interview Clozo is an AI interview copilot for real interview rounds: it hears the question and puts a strong answer on your screen, and you say it in your own words. See the features or how it works.
Start Free Trial →Cycle and pointer-speed questions
How do you detect a cycle in a linked list?
Floyd's cycle-finding algorithm is a method that moves two pointers through the list, a slow one a step at a time and a fast one two steps, and reports a cycle if they meet; if the fast pointer reaches null there is none. It is called the tortoise and hare, and a 2019 arXiv paper credits it to Floyd and cites Knuth, Section 3.1, Exercise 6 (arXiv 1901.01926). It uses O(n) time and O(1) space. On 1→2→3→4→5 with node 5 pointing back to 3, the pointers meet at node 4 after three steps.1
Why it is asked: it tests whether you can beat a hash set on space. Source: arXiv 1901.01926. For the graph version, read the full explanation: detecting a cycle in a directed graph.
How do you find the node where the cycle starts?
You find the cycle start by leaving one pointer at the meeting point, moving the other to the head, and stepping both one node at a time until they meet. Why: with a nodes before the cycle, length L and b steps from its start to the meeting point, slow walked a plus b and fast twice that, so a plus b is a multiple of L. In the example a is 2, L is 3, b is 1, and phase two takes two steps to reach node 3.1
Why it is asked: it separates memorised code from the argument. Source: arXiv 1901.01926.
How do you find the middle node of a linked list?
You find the middle node in one pass with a slow pointer and a fast pointer: move slow one step and fast two, and when fast cannot move further, slow is at the middle. Five nodes give the third node. Four nodes have two middles, and the usual loop condition returns the second, node 3 of [1,2,3,4].1 Ask which middle is wanted, and for odd and even lengths state it before you code.
Why it is asked: it is a small test of the two-speed idea and of edge-case care. Read the full explanation: Coding interview questions: the patterns and the method.
How do you check whether a linked list is a palindrome?
You check a linked list for a palindrome by finding the middle with slow and fast pointers, reversing the second half in place, comparing the halves node by node, and reversing the second half back to restore the list. That takes O(n) time and O(1) extra space. [1,2,2,1] gives true and [1,2,3] gives false.1 LeetCode 234 asks this (LeetCode 234, accessed October 2026).
Why it is asked: it combines the middle and reversal moves and tests whether you restore the input. Read the full explanation: Coding interview questions: the patterns and the method.
How do you find the intersection of two linked lists?
You find where two singly linked lists meet by walking one pointer along each list and, when a pointer reaches the end, restarting it at the other list's head; the pointers meet at the shared node, or both become null if there is none. Time is O(n plus m) and space O(1). For [4,1,8,4,5] and [5,6,1,8,4,5] sharing the tail from 8, they meet at that node after 9 moves, including the two switches to the other head.1 See LeetCode 160 (LeetCode 160, accessed October 2026).
Why it is asked: it tests whether you can equalise two unequal walks without extra memory. Read the full explanation: Coding interview questions: the patterns and the method.
Merging, copying and design questions
How do you merge two sorted linked lists?
You merge two sorted linked lists with a dummy node and a tail pointer: compare the two heads, attach the smaller node to the tail and advance that list, then attach whichever list remains. Merging [1,3,5] and [2,4,6] gives [1,2,3,4,5,6] in six attach steps.1 Time is O(n plus m) for lists of n and m nodes, and extra space is O(1) because the existing nodes are relinked, not copied. The same compare-and-advance sweep appears in merge intervals.
Why it is asked: it checks clean pointer handling with a dummy node. Read the full explanation: Merge intervals: the sort-and-sweep solution.
How do you copy (clone) a linked list with a random pointer?
You copy a linked list with a random pointer by building exactly n brand-new nodes whose pointers point only to new nodes (statement as mirrored, accessed October 2026). Method one: a hash map from each old node to its copy, O(n) extra space; a defaultdict or plain dict works. Method two: insert each copy after its original, set the random pointers, then split the lists, O(1) extra space beyond the output. An OpenAI candidate reported this.1
Why it is asked: it tests whether you understand what a deep copy means. Source: LeetCode 138.
How do you design a doubly linked list with insert, delete and search?
You design a doubly linked list with nodes that hold a value, a previous reference and a next reference, plus two sentinel nodes at the ends so that insert and delete need no special cases. Insert after a node by setting four references. Delete by pointing the node's previous at its next and its next at its previous. Search walks from the head, O(n), unless you add a hash map from value to node. An Anduril candidate reported this design question.
Why it is asked: it tests application programming interface (API) design and invariants, not one trick. Read the full explanation: Coding interview questions: the patterns and the method.
How do you design a least recently used (LRU) cache?
You build a least recently used (LRU) cache from a hash map of key to node and a doubly linked list ordered by recent use: each successful get or put moves the node to the front, and when the cache is over capacity you remove the node at the back. Both operations are O(1). With capacity 2, put 1, put 2, get 1, put 3 evicts key 2.1 This is LeetCode 146 (LeetCode 146, accessed October 2026).
Why it is asked: it joins a hash map to the doubly linked list design above. Read the full explanation: Coding interview questions: the patterns and the method.
How do you remove the n-th node from the end in one pass?
You remove the n-th node from the end in one pass with two pointers kept n nodes apart, starting from a dummy node before the head; when the fast pointer reaches the last node, the slow pointer sits just before the target. Set its next pointer to skip the target. The dummy node handles removing the head itself. On [1,2,3,4,5] with n = 2 the result is [1,2,3,5].1
Why it is asked: it tests the fixed-gap two-pointer pattern. Read the full explanation: Coding interview questions: the patterns and the method.
Follow-up questions
What are the most common linked list interview questions?
Reversal and its variants (the whole list, a sublist, groups of k, pairs), cycle detection and the cycle start, the middle node, the palindrome check, the intersection of two lists, merging two sorted lists, copying with a random pointer, designing a doubly linked list, and the cache that builds on it. Most reduce to a few moves: a dummy node, two pointers, and careful pointer order. The wider set of patterns is in the coding interview guide.
Which linked list questions have candidates reported?
The question bank for this topic holds candidate reports, not confirmed company practice: group reversal from Amazon and NVIDIA candidates, sublist reversal from a Salesforce candidate, the random-pointer copy from an OpenAI candidate, a doubly linked list design from an Anduril candidate, and a hard linked-list problem in a Microsoft onsite. None has a public source, so treat them as examples of the shape, not as a prediction.
How do I practise linked list problems?
Draw boxes and arrows and trace the pointer changes by hand on a three-node list before you write code. Then say each pointer assignment aloud as you type it. Redo a problem a day later without notes, and confirm the output on a short example by running it, as the traces on this page were run.
Which edge cases should I test on a linked list problem?
Test an empty list, a single node, two nodes, removal or change at the head, a list shorter than k, and a list with a cycle if the problem allows one. Most wrong answers fail on the first, second or head case, so name them to the interviewer before you start.
- A linked list gives cheap relinking once you hold a node, but reaching a position means walking the list.
- Reversal keeps a previous pointer, a current pointer and a saved next pointer; the sublist, group and pair variants reuse that loop.
- Floyd's two-speed pointers find a cycle in O(1) space, and a second phase finds where it starts.
- A dummy node removes head special cases in merge, sublist, pair and removal problems.
- Python has no built-in linked list, and Java's
LinkedListstill walks to reach an index.
Sources
- Reverse Linked List (LeetCode 206) — LeetCode, 26 Oct 2026
- Reverse Linked List II (LeetCode 92) — LeetCode, 26 Oct 2026
- LinkedList (Java SE 17 and JDK 17) — Oracle, 26 Oct 2026
- collections: container datatypes (Python documentation) — Python Software Foundation, 26 Oct 2026
- CPython Modules/_collectionsmodule.c, comment block (tag v3.7.3) — Python Software Foundation (CPython repository), 25 Mar 2019
- An in-place, subquadratic algorithm for permutation inversion (arXiv 1901.01926) — arXiv, 7 Jan 2019
- Copy List with Random Pointer (LeetCode 138), problem statement as mirrored — doocs/leetcode (GitHub mirror), 26 Oct 2026
- Copy List with Random Pointer (LeetCode 138) — LeetCode, 26 Oct 2026
- LRU Cache (LeetCode 146) — LeetCode, 26 Oct 2026
- Palindrome Linked List (LeetCode 234) — LeetCode, 26 Oct 2026
- Intersection of Two Linked Lists (LeetCode 160) — LeetCode, 26 Oct 2026