How to make the fast pointer to move kth node further and perhaps a single node .can i use loop for that purpose lets say
for(int i=0;i<k;i++){
fast=fast->next;
i++;
}
or any optimal solution ?
How to make the fast pointer to move kth node further and perhaps a single node .can i use loop for that purpose lets say
for(int i=0;i<k;i++){
fast=fast->next;
i++;
}
or any optimal solution ?
Yes you can do like this . Moving the fast pointer k steps ahead beforehand.And then move both fast and slow pointer at the same rate.
for(int i=0;i<k;i++){
fast=fast->next;
}
Since this is a linked list, its an optimal way as any case you need to traverse all nodes.
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.
Page is not opening …