In-place List Reversal
LC #61Medium
Rotate List
In-place List Reversal
AmazonGoogleMicrosoftProblem
Rotate a linked list to the right by k places.
linked-list
Constraints
- ›0 ≤ n ≤ 500
- ›-100 ≤ Node.val ≤ 100
- ›0 ≤ k ≤ 2 × 10⁹
Example
Input
head = [1, 2, 3, 4, 5], k = 2Output
[4, 5, 1, 2, 3]Why
Rotate right by 2: last 2 nodes [4,5] move to front