Ek test m run error q araha hai? am i miss any corner cases?
hi @sroy3166
run error is because of
while(fast->next!=NULL)
{
slow = slow->next;
fast = fast->next;
}
if fast==NULL then you are trying to access NULL->next which is giving run error
correct one
while(fast&&fast->next!=NULL)
{
slow = slow->next;
fast = fast->next;
}
but this will give wrong ans
for this input
5 4 3 2 1-1
5
you output is 4
but correct ans is 5
make one change
at line 28 add this line
if(fast==NULL)return head;
modified code