Solution using Recursion!


#1

void rotate(ListNode* &head,ListNode *A,int &count,int &k)
{
if(A->next != NULL)
{
count++;
rotate(head,A->next,count,k);
}
else{
count++;
k = k%count;
A->next = head;
count = 1;
}

 if(count == k+1)
 {
     head = A->next;
     A->next = NULL;
 }
 count++;

}
ListNode* Solution::rotateRight(ListNode* A, int B) {
int count = 0;

rotate(A,A,count,B);
return A;

}