Rotate List
Given the head of a linked list, rotate the list to the right by k places.

30:00

Rotate List
medium
Topics
Companies

Given the head of a linked list, rotate the list to the right by k places.

Example 1:
Input: {"head":[1,2,3,4,5],"k":2}
Output: [4,5,1,2,3]
Constraints:
  • The number of nodes is in the range [0,500][0, 500].

  • 100Node.val100-100 \leq \text{Node.val} \leq 100

  • 0k2×1090 \leq k \leq 2 \times 10^9

Input
arr ={"head":[1,2,3,4,5],"k":2}

Rotate list by 2 positions to the right

k = 2
Current
New Head
Linked List
head

1

0

2

1

3

2

4

3

5

4

null

Phase: counting

Variables
No variables to display
DepthFunction Call
Stack empty
0/11