Browse curriculum

Linked List

Linked List Interview Questions: The Linked List Pattern

Pointer manipulation with no random access. Almost every linked list technique is one of three moves: run two pointers at different speeds, reverse a section in place, or use a dummy head so the first node needs no special case. Below are the linked list interview questions from LeetCode, each with a step-by-step visual solution.

23

Interactive problems

19

Free to open

Recognise

How do you recognise a linked list problem?

The input is a list rather than an array, and the question asks about cycles, the nth node from the end, reordering, or comparing the list against itself. The giveaway constraint is "do it in one pass" or "use O(1) extra space": both rule out copying into an array.

Complexity

What is the time complexity of the linked list pattern?

O(n) time and O(1) extra space for the pointer techniques. Copying into an array also gives O(n) time but costs O(n) space, which is usually the thing being tested.

Problems

Linked List interview questions: practice problems

Each problem pairs a worked explanation with an interactive visualizer you step through yourself, plus the implementation in JavaScript, Python, Java and C++.

Complexity

Linked List problems by difficulty and complexity

The difficulty, running time and extra space of every linked list solution on this page, as each lesson derives them.

LessonDifficultyBestAverageWorstSpace
Linked List OverviewEasyΩ(n)Θ(n)O(n)O(1)
Reverse Linked ListEasyΩ(n)Θ(n)O(n)O(1)
Middle of the Linked ListEasyΩ(n)Θ(n)O(n)O(1)
Delete the Middle Node of a Linked ListMediumΩ(1)Θ(n)O(n)O(1)
Odd Even Linked ListMediumΩ(1)Θ(n)O(n)O(1)
Maximum Twin Sum of a Linked ListMediumΩ(n)Θ(n)O(n)O(1)
Intersection of Two Linked ListsEasyΩ(1)Θ(m + n)O(m + n)O(1)
Merge Two Sorted ListsEasyΩ(min(n, m))Θ(n + m)O(n + m)O(1)
Add Two NumbersMediumΩ(max(m, n))Θ(max(m, n))O(max(m, n))O(max(m, n))
Linked List CycleEasyΩ(1)Θ(n)O(n)O(1)
Linked List Cycle IIMediumΩ(n)Θ(n)O(n)O(1)
Sort ListMediumΩ(n log n)Θ(n log n)O(n log n)O(log n)
Rotate ListMediumΩ(n)Θ(n)O(n)O(1)
Palindrome Linked ListEasyΩ(n)Θ(n)O(n)O(1)
Remove Nth Node From End of ListMediumΩ(n)Θ(n)O(n)O(1)
Reorder ListMediumΩ(n)Θ(n)O(n)O(1)
Swap Nodes in PairsMediumΩ(n)Θ(n)O(n)O(1)
LRU CacheMediumΩ(1)Θ(1)O(1)O(capacity)
LFU CacheHardΩ(1)Θ(1)O(1)O(capacity)
Find the Duplicate NumberMediumΩ(1)Θ(n)O(n)O(1)
Copy List with Random PointerMediumΩ(n)Θ(n)O(n)O(n)
Reverse Nodes in k-GroupHardΩ(n)Θ(n)O(n)O(1)
Happy NumberEasyΩ(1)Θ(log n)O(log n)O(1)
Curriculum

The underlying technique is covered from first principles in the linked list lesson in the DSA visualizer curriculum. Linked List is one of the 18 coding interview patterns, and its problems also appear in the DSA 75 interview sprint.

Directory

Every other coding interview pattern