educative.io

Middle of the Linked List

Not sure why this below code is Not getting accepted

// Your code will replace this placeholder return statement

EduLinkedListNode* slow =head;

EduLinkedListNode* fast =head;

while(fast->next && fast ){

slow=slow->next;

fast=fast->next->next;

}

return slow;


Course: https://www.educative.io/courses/grokking-coding-interview-patterns-cpp
Lesson: Middle of the Linked List - Grokking Coding Interview Patterns in C++

Hi @GAURAV_KUMAR
The while loop condition should be like this:
while(fast && fast-> next)
first, we check the fast pointer to see if it exists, then we check the fast->next pointer.

Kindly update your while loop condition with this modification and retry. This should work.