Linked List Interview Patterns

Common linked list patterns intersection, reverse in k-group, palindrome, cycle entry

#resource / algorithm #type / concept #status / growing #ds / linked-list

[!info] related notes 算法面试题型 MOC

Linked List Interview Patterns

Intersection of Two Acyclic Lists

  • Let the longer list advance abs(lenA - lenB) steps first.
  • Then move both pointers together; the first equal node is the intersection.

Reverse Nodes in k-Group

  • Pattern: locate a k-sized block, reverse it, connect tail to next block.
  • Key: you need the previous block’s tail to reconnect.

Copy List with Random Pointer

  • Common patterns:
    • HashMap old->new.
    • Interleaving nodes (clone node inserted after original) then split.

Palindrome List

  • Fast/slow pointers find middle.
  • Reverse second half.
  • Compare two halves.
  • Optional: restore the list by reversing back.
// compare halves after reversing from mid
// (template only; adapt to your ListNode definition)

Cycle Entry Node

  • HashSet method: record visited nodes.
  • Floyd method:
    • First meet: fast and slow.
    • Then set one pointer to head, both move 1 step; next meet is the entry.
创建于 2026/3/16 更新于 2026/5/27