Problem Challenge 2

Rotate a LinkedList (medium) #

Given the head of a Singly LinkedList and a number ‘k’, rotate the LinkedList to the right by ‘k’ nodes.

Created with Fabric.js 1.6.0-rc.1 Original List: head head k=3 1 2 3 4 5 6 null 4 5 6 1 2 3 null Rotated LinkedList: Example 1:
Created with Fabric.js 1.6.0-rc.1 Original List: head head Rotated LinkedList: 1 2 3 4 5 null Example 2: k=8 3 4 5 1 2 null

Try it yourself #

Try solving this question here:

Output

0.491s

Nodes of original LinkedList are: 1 2 3 4 5 6 Nodes of rotated LinkedList are: 1 2 3 4 5 6

Mark as Completed
←    Back
Solution Review: Problem Challenge 1
Next    →
Solution Review: Problem Challenge 2