Rotate List

Medium

Question

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

Rotate List Example 1

Input: head = [1 -> 2 -> 3], k = 4

Output: [3 -> 1 -> 2]

Rotate List Example 2

Input: head = [1 -> 2 -> 3 -> 4 -> 5], k = 2

Output: [4 -> 5 -> 1 -> 2 -> 3]

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

What is the resulting list after rotating it by 5 places? head = [0 -> 2 -> 4]
[0 -> 2 -> 4]
[2 -> 4 -> 0]
[4 -> 0 -> 2]
[4 -> 2 -> 0]

Login or signup to save your code.

Notes