Dashboard
LC #61

Rotate List

Pattern · ?AmazonGoogleMicrosoft

Problem

Rotate a linked list to the right by k places.

Constraints

  • 0 ≤ n ≤ 500
  • -100 ≤ Node.val ≤ 100
  • 0 ≤ k ≤ 2 × 10⁹

Example

Input
head = [1, 2, 3, 4, 5], k = 2
Output
[4, 5, 1, 2, 3]
Why
Rotate right by 2: last 2 nodes [4,5] move to front

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗