loading

Rotate List — Step-by-Step Visualization

mediumLeetCode #61Linked ListTwo Pointers

Rotate linked list to the right by k places.

Algorithm Pattern

Find New Tail + Reconnect

Key Idea

Rotation = cut list at n-k and reattach the back to the front.

Step-by-Step Approach

  1. Find length n
  2. k = k % n
  3. Advance to node at n-k-1
  4. Reconnect: new_tail.next.prev=tail, tail.next=old_head, new_tail.next=null

Related Problems