Tensorum

Linked List

Fast and slow pointers, in-place reversal, merging and pointer-surgery designs like LRU.

DSABeginner18 hrs11 patterns · 29 problems
0%
your progress

Core idea

Use a dummy head to remove edge cases, fast/slow pointers for distance problems, and reverse in place with three pointers (prev, cur, next).

Reach for it when

  • In-place reordering, reversal or merging of nodes
  • Cycle detection or finding the middle
  • LRU-style O(1) insert/remove designs

Template

def reverse(head):
    prev = None
    while head:
        head.next, prev, head = prev, head, head.next
    return prev

Complexity

O(n) time, O(1) extra space for nearly every pattern.

Common pitfalls

  • Losing the rest of the list by overwriting next too early
  • Not handling empty or single-node lists
  • Forgetting to cut the tail when splitting

Recognition cues

Two PointersReverseMergeCycleReorderingDesign