dsapatterns©
01Home02Patterns03Questions04
Cheatsheet
05Notes06Dashboard

© 2026 DSAPatterns

dsapatterns©
Cheatsheet
dsapatterns©
01Home02Patterns03Questions04
Cheatsheet
05Notes06Dashboard

© 2026 DSAPatterns

dsapatterns©
Cheatsheet
dsapatterns©
01Home02Patterns03Questions04
Cheatsheet
05Notes06Dashboard

© 2026 DSAPatterns

dsapatterns©
Cheatsheet
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 ⟲
Linked ListO(n) traverse
HEAD
3
→
7
→
12
→
5
→
9
→
null
head → node(3)
Linked List Cheatsheet
FLIP SIDELinked List
Tap to flip back ⟲

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.

✓ SELECTED

Reversal

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

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

Fast & Slow Pointers

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

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

Dummy Head / Sentinel Node

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

  • Remove Nth Node From End of List
  • Merge Two Sorted Lists
  • Remove Duplicates from Sorted List II
5 problems

Merge / Sort Linked Lists

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

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

In-place Node Manipulation

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

  • Swap Nodes in Pairs
  • Rotate List
  • Odd Even Linked List
5 problems

Two Pointers — Kth & Intersection

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

  • Remove Nth Node From End of List
  • Intersection of Two Linked Lists
  • Middle of the Linked List
5 problems
2

Template / Approach

Template for: Reversal

Approach

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

</>Common Template
💡Universal iterative reversal skeleton. Works for full reversal, and is a building block for partial reversal (reverse between positions) and k-group reversal.
🔑
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.
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}
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

dsapatterns

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

  • Notes

© 2026 DSAPATTERNS. ALL RIGHTS RESERVED.

DESIGNED & BUILT WITH CARE

FAQsPrivacy PolicyCookies Policy