patternlens©
01Home02Patterns03Questions04Cheatsheet05Notes06Roadmaps07Dashboard

© 2026 PatternLens

patternlens©
Explore
HomePatternsQuestionsCheatsheetNotes
patternlens©
01Home02Patterns03Questions04Cheatsheet05Notes06Roadmaps07Dashboard

© 2026 PatternLens

patternlens©
Explore
HomePatternsQuestionsCheatsheetNotes
Cheatsheet›Linked List
CORE PATTERNHigh Frequency

Linked List

Linked lists are chains of nodes connected by pointers. Unlike arrays, nodes are not contiguous in memory.

TimeO(N)
SpaceO(1)
DifficultyEasy to Hard

Key Insight

Follow the pointers — every problem is a pointer manipulation.

Flip ⟲

Flip for Infographic

Interactive infographic on the flip side.

Click anywhere to Flip ⟲
FLIP SIDELinked List
Click anywhere to flip back ⟲
Linked List Cheatsheet

Recognition Signals (When to use this pattern)

  • →Reverse a linked list or part of it
  • →Detect or find the start of a cycle
  • →Find the middle node or kth from the end
  • →Merge two or more sorted lists
  • →Remove or reorder nodes in-place
  • →Clone a list with random / next pointers
1

Types of Problems (Subpatterns)

Each subpattern solves a specific type of problem. Click on a card to view its template.

Reversal

Flip pointer directions iteratively or recursively — the core of most reorder problems.

Common Problems

  • • Reverse Linked List
  • • Reverse Linked List II
  • • Reverse Nodes in k-Group
  • • Palindrome Linked List
  • • Swap Nodes in Pairs
5 problems

Fast & Slow Pointers

Slow moves 1 step, fast moves 2 — cycle detection and midpoint finding.

Common Problems

  • • Linked List Cycle
  • • Linked List Cycle II
  • • Middle of the Linked List
  • • Reorder List
  • • Palindrome Linked List
5 problems

Dummy Head / Sentinel Node

A dummy node before the head eliminates edge cases for head removal and list building.

Common Problems

  • • Remove Nth Node From End of List
  • • Merge Two Sorted Lists
  • • Remove Duplicates from Sorted List II
  • • Partition List
  • • Delete Node in a Linked List
5 problems

Merge / Sort Linked Lists

Merge sorted lists by comparing heads and stitching the smaller node first.

Common Problems

  • • Merge Two Sorted Lists
  • • Merge K Sorted Lists
  • • Sort List
  • • Insertion Sort List
  • • Reorder List
5 problems

In-place Node Manipulation

Rewire next pointers directly — no extra nodes, no copying values.

Common Problems

  • • Swap Nodes in Pairs
  • • Rotate List
  • • Odd Even Linked List
  • • Delete Node in a Linked List
  • • Copy List with Random Pointer
5 problems

Two Pointers — Kth & Intersection

Create a gap of k between two pointers to find the kth-from-end or the intersection node.

Common Problems

  • • Remove Nth Node From End of List
  • • Intersection of Two Linked Lists
  • • Middle of the Linked List
  • • Find the Duplicate Number (Floyd's on array)
  • • Linked List Cycle II
5 problems
2

Template / Approach

Template for: Reversal

1

Track Three Pointers

Keep prev = nullptr, curr = head, and next = nullptr before the loop begins.

2

Save Next

Store next = curr->next before overwriting the pointer — otherwise you lose the rest of the list.

3

Flip and Advance

Set curr->next = prev, then advance: prev = curr, curr = next. Repeat until curr is nullptr.

4

Return New Head

When the loop ends, prev points to the new head of the reversed list.

template_cpp
💡 Universal iterative reversal skeleton. Works for full reversal, and is a building block for partial reversal (reverse between positions) and k-group reversal.
1// Iterative reversal — O(N) time, O(1) space
2ListNode* reverseList(ListNode* head)
3{
4   ListNode* prev = nullptr;
5   ListNode* curr = head;
6
7   while (curr)
8   {
9      ListNode* next = curr->next; // save before overwriting
10
11      curr->next = prev; // flip pointer
12      prev = curr; // advance prev
13      curr = next; // advance curr
14   }
15
16   return prev; // new head
17}
Key Idea:Reversal requires exactly three pointers: prev (already reversed), curr (being processed), next (saved before overwrite). The direction of curr->next flips each iteration — no extra space needed.

Practice Problems

Sharpen your skills with hand-picked problems.

View All Problems
Easy

Reverse Linked List

LeetCode #206

Medium

Reverse Linked List II

LeetCode #92

Hard

Reverse Nodes in k-Group

LeetCode #25

Medium

Swap Nodes in Pairs

LeetCode #24

Easy

Linked List Cycle

LeetCode #141

Medium

Linked List Cycle II

LeetCode #142

Easy

Middle of the Linked List

LeetCode #876

Medium

Reorder List

LeetCode #143

Easy

Palindrome Linked List

LeetCode #234

Medium

Remove Nth Node From End of List

LeetCode #19

Easy

Merge Two Sorted Lists

LeetCode #21

Medium

Remove Duplicates from Sorted List II

LeetCode #82

Medium

Partition List

LeetCode #86

Hard

Merge K Sorted Lists

LeetCode #23

Medium

Sort List

LeetCode #148

Medium

Insertion Sort List

LeetCode #147

Medium

Odd Even Linked List

LeetCode #328

Medium

Rotate List

LeetCode #61

Medium

Copy List with Random Pointer

LeetCode #138

Medium

Delete Node in a Linked List

LeetCode #237

Easy

Intersection of Two Linked Lists

LeetCode #160

Medium

Find the Duplicate Number

LeetCode #287

Medium

LRU Cache

LeetCode #146

patternlens.

See the patterns. Master the algorithms. Ace the interviews.

Visual DSA pattern library built to turn complex algorithms into clear, intuitive structures.

Learn

  • Patterns
  • Questions
  • Notes
  • Cheatsheet

Build

  • Roadmaps
  • Notes

© 2026 PatternLens. All rights reserved.

Designed & built with care

FAQsPrivacy PolicyCookies Policy