Check the code###

Heyy, My code gets submittted for all the test cases but its not correct because it will fail in the case where the input is 1 2 3 1.
how should i correct it ? Here I m calling the function as pass by value so my original linklist should not change but when i call print function for the original head only one element gets printed. I’m not able to compare the elements of both the linklist.

hi,
in ur code, the palindrome function is just reversing the string.
so newhead is reverse of head.
in order to see whether the given linked list is a palindrome, you should traverse both the linked list till middle element of both the list and compare them instead of just comparing there head->data.

Yes I know but on comparing it doesn’t work because in original linklist only one element is there

Instead of what u r doing right now, you can follow a different approach.
->first traverse the original linked list till middle element.
->break the linked list at that point(say ‘a’) and store the linked list after ‘a’ in head2 and reverse head2.
-> now just compare head2 with the original broken linked list.

Okayy, I’ll try…

Hi, I hope your doubt was resolved.
If it was, please mark this doubt resolved.
else if you are still facing any problem in this question, you can post it here.