Episode 7 — DSA with JavaScript / 7.12 — Linked List

7.12.a — Linked Lists: Singly, Doubly, Circular

<< 7.12 Overview


Node definition

Singly linked list:
  ┌──────┬──────┐    ┌──────┬──────┐    ┌──────┬──────┐
  │ val  │ next │───▶│ val  │ next │───▶│ val  │ next │───▶ null
  └──────┴──────┘    └──────┴──────┘    └──────┴──────┘
    head                                   tail

JavaScript

class ListNode {
    constructor(val, next = null) {
        this.val = val;
        this.next = next;
    }
}

C++

struct ListNode {
    int val;
    ListNode* next;
    ListNode(int v, ListNode* n = nullptr) : val(v), next(n) {}
};

Build & traverse

function buildList(arr) {
    let head = null;
    for (let i = arr.length - 1; i >= 0; i--)
        head = new ListNode(arr[i], head);
    return head;
}

function printList(head) {
    let curr = head;
    const parts = [];
    while (curr) { parts.push(curr.val); curr = curr.next; }
    console.log(parts.join(" → ") + " → null");
}
ListNode* buildList(vector<int>& arr) {
    ListNode* head = nullptr;
    for (int i = arr.size()-1; i >= 0; i--)
        head = new ListNode(arr[i], head);
    return head;
}

Reverse linked list

Before: 1 → 2 → 3 → null
After:  3 → 2 → 1 → null

Step-by-step:
  prev=null, curr=1
  next=2, curr.next=null, prev=1, curr=2
  next=3, curr.next=1,   prev=2, curr=3
  next=null, curr.next=2, prev=3, curr=null
  return prev → 3 → 2 → 1 → null
function reverse(head) {
    let prev = null, curr = head;
    while (curr) {
        const next = curr.next;
        curr.next = prev;
        prev = curr;
        curr = next;
    }
    return prev;
}
ListNode* reverse(ListNode* head) {
    ListNode* prev = nullptr;
    while (head) {
        ListNode* next = head->next;
        head->next = prev;
        prev = head;
        head = next;
    }
    return prev;
}

Detect cycle (Floyd's algorithm)

  1 → 2 → 3 → 4 → 5
               ↑       ↓
               8 ← 7 ← 6

Fast pointer moves 2 steps, slow moves 1.
If cycle exists, they will meet.
function hasCycle(head) {
    let slow = head, fast = head;
    while (fast && fast.next) {
        slow = slow.next;
        fast = fast.next.next;
        if (slow === fast) return true;
    }
    return false;
}

Find cycle start

function findCycleStart(head) {
    let slow = head, fast = head;
    while (fast && fast.next) {
        slow = slow.next;
        fast = fast.next.next;
        if (slow === fast) {
            slow = head;
            while (slow !== fast) { slow = slow.next; fast = fast.next; }
            return slow;
        }
    }
    return null;
}

Merge two sorted lists

function mergeTwoLists(l1, l2) {
    const dummy = new ListNode(0);
    let curr = dummy;
    while (l1 && l2) {
        if (l1.val <= l2.val) { curr.next = l1; l1 = l1.next; }
        else { curr.next = l2; l2 = l2.next; }
        curr = curr.next;
    }
    curr.next = l1 || l2;
    return dummy.next;
}

Remove nth from end

function removeNthFromEnd(head, n) {
    const dummy = new ListNode(0, head);
    let fast = dummy, slow = dummy;
    for (let i = 0; i <= n; i++) fast = fast.next;
    while (fast) { fast = fast.next; slow = slow.next; }
    slow.next = slow.next.next;
    return dummy.next;
}

Doubly linked list

  null ← ┌──────┬──────┬──────┐ ⇄ ┌──────┬──────┬──────┐ ⇄ ┌──────┬──────┬──────┐ → null
         │ prev │ val  │ next │   │ prev │ val  │ next │   │ prev │ val  │ next │
         └──────┴──────┴──────┘   └──────┴──────┴──────┘   └──────┴──────┴──────┘
class DNode {
    constructor(val, prev = null, next = null) {
        this.val = val;
        this.prev = prev;
        this.next = next;
    }
}

Circular linked list

  1 → 2 → 3 → 4
  ↑             │
  └─────────────┘

Last node's next points back to head.


Operations complexity

OperationSinglyDoubly
Access by indexO(n)O(n)
Insert at headO(1)O(1)
Insert at tailO(n)*O(1)**
Delete at headO(1)O(1)
Delete at tailO(n)O(1)
SearchO(n)O(n)

*O(1) if tail pointer maintained **with tail pointer


Scenario bank (linked list)

7.12a-001 — Reverse in groups of K (v1)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-002 — Find middle node (slow/fast) (v2)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-003 — Check palindrome linked list (v3)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-004 — Add two numbers (linked list) (v4)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-005 — Intersection of two lists (v5)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-006 — Remove duplicates from sorted list (v6)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-007 — Sort a linked list (merge sort) (v7)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-008 — Flatten a multilevel linked list (v8)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-009 — Copy list with random pointer (v9)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-010 — LRU Cache implementation (v10)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-011 — Rotate list by K (v11)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-012 — Swap nodes in pairs (v12)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-013 — Reorder list (L0→Ln→L1→Ln-1...) (v13)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-014 — Partition list around value (v14)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-015 — Delete node without head pointer (v15)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-016 — Odd-even linked list separation (v16)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-017 — Convert sorted list to BST (v17)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-018 — Find loop length in cycle (v18)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-019 — Merge K sorted lists (v19)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-020 — Clone linked list with random pointers (v20)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-021 — Reverse in groups of K (v21)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-022 — Find middle node (slow/fast) (v22)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-023 — Check palindrome linked list (v23)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-024 — Add two numbers (linked list) (v24)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-025 — Intersection of two lists (v25)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-026 — Remove duplicates from sorted list (v26)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-027 — Sort a linked list (merge sort) (v27)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-028 — Flatten a multilevel linked list (v28)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-029 — Copy list with random pointer (v29)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-030 — LRU Cache implementation (v30)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-031 — Rotate list by K (v31)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-032 — Swap nodes in pairs (v32)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-033 — Reorder list (L0→Ln→L1→Ln-1...) (v33)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-034 — Partition list around value (v34)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-035 — Delete node without head pointer (v35)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-036 — Odd-even linked list separation (v36)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-037 — Convert sorted list to BST (v37)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-038 — Find loop length in cycle (v38)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-039 — Merge K sorted lists (v39)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-040 — Clone linked list with random pointers (v40)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-041 — Reverse in groups of K (v41)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-042 — Find middle node (slow/fast) (v42)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-043 — Check palindrome linked list (v43)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-044 — Add two numbers (linked list) (v44)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-045 — Intersection of two lists (v45)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-046 — Remove duplicates from sorted list (v46)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-047 — Sort a linked list (merge sort) (v47)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-048 — Flatten a multilevel linked list (v48)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-049 — Copy list with random pointer (v49)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-050 — LRU Cache implementation (v50)

  • Level: Beginner
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-051 — Rotate list by K (v51)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-052 — Swap nodes in pairs (v52)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-053 — Reorder list (L0→Ln→L1→Ln-1...) (v53)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-054 — Partition list around value (v54)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-055 — Delete node without head pointer (v55)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-056 — Odd-even linked list separation (v56)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-057 — Convert sorted list to BST (v57)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-058 — Find loop length in cycle (v58)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-059 — Merge K sorted lists (v59)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-060 — Clone linked list with random pointers (v60)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-061 — Reverse in groups of K (v61)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-062 — Find middle node (slow/fast) (v62)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-063 — Check palindrome linked list (v63)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-064 — Add two numbers (linked list) (v64)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-065 — Intersection of two lists (v65)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-066 — Remove duplicates from sorted list (v66)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-067 — Sort a linked list (merge sort) (v67)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-068 — Flatten a multilevel linked list (v68)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-069 — Copy list with random pointer (v69)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-070 — LRU Cache implementation (v70)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-071 — Rotate list by K (v71)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-072 — Swap nodes in pairs (v72)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-073 — Reorder list (L0→Ln→L1→Ln-1...) (v73)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-074 — Partition list around value (v74)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-075 — Delete node without head pointer (v75)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-076 — Odd-even linked list separation (v76)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-077 — Convert sorted list to BST (v77)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-078 — Find loop length in cycle (v78)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-079 — Merge K sorted lists (v79)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-080 — Clone linked list with random pointers (v80)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-081 — Reverse in groups of K (v81)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-082 — Find middle node (slow/fast) (v82)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-083 — Check palindrome linked list (v83)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-084 — Add two numbers (linked list) (v84)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-085 — Intersection of two lists (v85)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-086 — Remove duplicates from sorted list (v86)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-087 — Sort a linked list (merge sort) (v87)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-088 — Flatten a multilevel linked list (v88)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-089 — Copy list with random pointer (v89)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-090 — LRU Cache implementation (v90)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-091 — Rotate list by K (v91)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-092 — Swap nodes in pairs (v92)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-093 — Reorder list (L0→Ln→L1→Ln-1...) (v93)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-094 — Partition list around value (v94)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-095 — Delete node without head pointer (v95)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-096 — Odd-even linked list separation (v96)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-097 — Convert sorted list to BST (v97)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-098 — Find loop length in cycle (v98)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-099 — Merge K sorted lists (v99)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-100 — Clone linked list with random pointers (v100)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-101 — Reverse in groups of K (v101)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-102 — Find middle node (slow/fast) (v102)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-103 — Check palindrome linked list (v103)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-104 — Add two numbers (linked list) (v104)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-105 — Intersection of two lists (v105)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-106 — Remove duplicates from sorted list (v106)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-107 — Sort a linked list (merge sort) (v107)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-108 — Flatten a multilevel linked list (v108)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-109 — Copy list with random pointer (v109)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-110 — LRU Cache implementation (v110)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-111 — Rotate list by K (v111)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-112 — Swap nodes in pairs (v112)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-113 — Reorder list (L0→Ln→L1→Ln-1...) (v113)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-114 — Partition list around value (v114)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-115 — Delete node without head pointer (v115)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-116 — Odd-even linked list separation (v116)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-117 — Convert sorted list to BST (v117)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-118 — Find loop length in cycle (v118)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-119 — Merge K sorted lists (v119)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-120 — Clone linked list with random pointers (v120)

  • Level: Intermediate
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-121 — Reverse in groups of K (v121)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-122 — Find middle node (slow/fast) (v122)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-123 — Check palindrome linked list (v123)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-124 — Add two numbers (linked list) (v124)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-125 — Intersection of two lists (v125)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-126 — Remove duplicates from sorted list (v126)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-127 — Sort a linked list (merge sort) (v127)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-128 — Flatten a multilevel linked list (v128)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-129 — Copy list with random pointer (v129)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-130 — LRU Cache implementation (v130)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-131 — Rotate list by K (v131)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-132 — Swap nodes in pairs (v132)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-133 — Reorder list (L0→Ln→L1→Ln-1...) (v133)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-134 — Partition list around value (v134)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-135 — Delete node without head pointer (v135)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-136 — Odd-even linked list separation (v136)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-137 — Convert sorted list to BST (v137)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-138 — Find loop length in cycle (v138)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-139 — Merge K sorted lists (v139)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-140 — Clone linked list with random pointers (v140)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-141 — Reverse in groups of K (v141)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-142 — Find middle node (slow/fast) (v142)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-143 — Check palindrome linked list (v143)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-144 — Add two numbers (linked list) (v144)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-145 — Intersection of two lists (v145)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-146 — Remove duplicates from sorted list (v146)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-147 — Sort a linked list (merge sort) (v147)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-148 — Flatten a multilevel linked list (v148)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-149 — Copy list with random pointer (v149)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-150 — LRU Cache implementation (v150)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-151 — Rotate list by K (v151)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-152 — Swap nodes in pairs (v152)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-153 — Reorder list (L0→Ln→L1→Ln-1...) (v153)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-154 — Partition list around value (v154)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-155 — Delete node without head pointer (v155)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-156 — Odd-even linked list separation (v156)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-157 — Convert sorted list to BST (v157)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-158 — Find loop length in cycle (v158)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-159 — Merge K sorted lists (v159)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-160 — Clone linked list with random pointers (v160)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-161 — Reverse in groups of K (v161)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-162 — Find middle node (slow/fast) (v162)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-163 — Check palindrome linked list (v163)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-164 — Add two numbers (linked list) (v164)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-165 — Intersection of two lists (v165)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-166 — Remove duplicates from sorted list (v166)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-167 — Sort a linked list (merge sort) (v167)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-168 — Flatten a multilevel linked list (v168)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-169 — Copy list with random pointer (v169)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.

7.12a-170 — LRU Cache implementation (v170)

  • Level: Advanced
  • Approach: Apply technique.
  • Time/Space: Analyze.
  • Edge cases: empty, single, boundary.
  • JS & C++: Both.