Skip to content
We areTOP 1%
DSA · Beginner · Pattern 8 of 11

Linked List

14 problems.
Your progress0%
1st Visit
0/14
2nd Visit
0/14
Revise
0/14

About this pattern

A singly linked list stores nodes that point to their successor, so insertion and deletion are O(1) once you hold the right node, but reaching the k-th node takes O(k). Most problems reduce to a handful of pointer techniques: reversing links in place, a dummy head node that removes special cases at the front, slow and fast pointers that find the middle or detect a cycle, and two pointers kept a fixed gap apart.

Draw the pointers before coding and update next fields in an order that never loses the rest of the list. Solutions usually take O(n) time and O(1) extra space.

// Reverse a list in place.
ListNode* reverseList(ListNode* head) {
    ListNode* prev = nullptr;
    while (head) {
        ListNode* nxt = head->next;   // save the rest first
        head->next = prev;
        prev = head;
        head = nxt;
    }
    return prev;
}
// Middle node: fast moves two steps for each step of slow.
ListNode* slow = head; ListNode* fast = head;
while (fast && fast->next) { slow = slow->next; fast = fast->next->next; }

Problems

Linked List questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Middle of the Linked ListLeetCodeEasy Solve Middle of the Linked List on LeetCode (opens in a new tab)
2Reverse Linked ListLeetCodeEasy Solve Reverse Linked List on LeetCode (opens in a new tab)
3Merge Two Sorted ListsLeetCodeEasy Solve Merge Two Sorted Lists on LeetCode (opens in a new tab)
4Remove Linked List ElementsLeetCodeEasy Solve Remove Linked List Elements on LeetCode (opens in a new tab)
5Linked List CycleLeetCodeEasy Solve Linked List Cycle on LeetCode (opens in a new tab)
6Intersection of Two Linked ListsLeetCodeEasy Solve Intersection of Two Linked Lists on LeetCode (opens in a new tab)
7Palindrome Linked ListLeetCodeEasy Solve Palindrome Linked List on LeetCode (opens in a new tab)
8Remove Nth Node From End of ListLeetCodeMedium Solve Remove Nth Node From End of List on LeetCode (opens in a new tab)
9Odd Even Linked ListLeetCodeMedium Solve Odd Even Linked List on LeetCode (opens in a new tab)
10Swap Nodes in PairsLeetCodeMedium Solve Swap Nodes in Pairs on LeetCode (opens in a new tab)
11Rotate ListLeetCodeMedium Solve Rotate List on LeetCode (opens in a new tab)
12Linked List Cycle IILeetCodeMedium Solve Linked List Cycle II on LeetCode (opens in a new tab)
13Reorder ListLeetCodeMedium Solve Reorder List on LeetCode (opens in a new tab)
14Copy List with Random PointerLeetCodeMedium Solve Copy List with Random Pointer on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account