Pls check the code..it is giving segmentation fault
hello @sneha23
a) 
here u need to increment q
also u should first updated prev and then update cur
prev=cur
cur=cur->next;
b)

u need to update head of the linked list .
still not runnig
there r so many mistakes in ur algorithm .
i would recommend to revise the algorithm again(specially that two pointer logic) and then try to implement.
OK I will revise those…but for now could you please tell me the mistakes in my code
first u need to fint n-kth node (here prev has no role, so no need to use it prev inside ur first loop).
now once u have found n-kth node , u need to shift both the pointers (one which is at n-k and one which is at 1st position one by one )
till ur n-kth node reach the end.
here u are only shifting n-kth node and not the first pointer which is a big mistake
check this ->
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;
}
just take it as reference.
a) first finding kth node
b) shifting both pointers(one which is at k and one which is at 1) one by one till the kth pointer reach the end.
c) updating heads
hey urs approach is different than what i suggested .
here is ur updated code.
btw do check the other approach as well it is efficient
i think u have shared some other questions’s code
sry , check now->
it is again of some diff ques
check again , i have updated it now
did u get ur updated code or should i share new link?
yes thankyou so much!
going through that only
sorry for troubling
thanx for being cooperative always:)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
