Browse curriculum

Linked List

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.

8

Interactive problems

8

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 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)
Merge Two Sorted ListsEasyΩ(min(n, m))Θ(n + m)O(n + m)O(1)
Linked List CycleEasyΩ(1)Θ(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)
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 17 coding interview patterns, and its problems also appear in the DSA 75 interview sprint.

Directory

Every other coding interview pattern