logo
Interview
    Interview Guide
    Coding Problems List
Sponsored: Coursera
Problems

Rotate List

Problem

Given a list, rotate the list to the right by k places, where k is non-negative.

Example

Given 1->2->3->4->5 and k = 2, return 4->5->1->2->3.

Solutions

Note that k might be larger than the size of the list, so we actually only rotates for k % size times.

Once we have the size and the modified k, we can move a pointer to the size - k-th node, then it is straight forward to update the links.

Online Judge