educative.io

Problem Challenge 1 Solution

Could someone please tell me how internally does the line -

reverse(copy_head_second_half) # revert the reverse of the second half

impact the solution. Why does the solution fail if we don’t reverse this?

Hey @Sumit_Sunil_Khopkar!
We have reversed the second half to see if the LinkedList represents a palindrome or not. reverse(slow) reversed the second half.
We will reverse the second half of the LinkedList again to revert and bring the LinkedList back to its original form.