Please check the code and mark the error

Hello, @anmolaggarwal.432,

Change your fast pointer initializtion:

ListNode* fast = head->next;

Ya I got right it just want to know that i submitted mid point on leetcode with fast = head->next it showed error testcase did not get passed PLease resolve this

@anmolaggarwal.432,

Let’s consider a simple linked list [ 3 -> 2 -> NULL ].

When fast = head, in the first iteration,
Your code will return midpoint as a node pointing to 2,
A will be pointing to 3 while B will be pointing to NULL,
So, A = 3 -> 2 -> NULL and B = NULL

Now, when A = Sortlist(A) is called, we would go back to the same position as in the first iteration ultimately leading to an infinite loop and the error.

Moreover,
For the given List midpoint should be 3 instead of 2.

@anmolaggarwal.432,
Is it clear now?

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.