Whats wrong with my code?

hello @akash_281
what issue u r facing?

I am getting segmentation fault

image

a) u r not incrementing ur count variable inside while loop

b) u need to add tail the list to the head of older list ,which u r not doing.
make these two changes and it will work.

also do k=k%n for making value of k < n.

for refrence ->

node* appendK(node *head,int k){
    node *oldHead = head;
    node *fast = head;
    node *slow = head;
    for(long i=0;i < k && fast->next!=NULL ;i++){
        fast = fast->next;
    }
    while(fast->next!=NULL && fast!=NULL){
        fast = fast->next;
        slow = slow->next;
    }
    node *newHead = slow->next;
    slow->next = NULL;
    fast->next = oldHead;
    return newHead;
}