Rotate a Linked List
Given the head of a singly linked list and an integer 'n' rotate the linked list by 'n'.
We'll cover the following
Given the head of a singly linked list and an integer
n, rotate the linked list by
n and return the rotated linked list.
Below is an example of sample input and expected output linked list after rotating by .
Note: The value of
ncan be larger than the length of the linked list.
[1, 2, 3, 4, 5] 2
[4, 5, 1, 2 ,3]
Note: For positive integers, we’ll do a positive rotation and for negative integers, we’ll do a left rotation.