say we have a string: MALAYALAM, and each char is data part of each node, so we will have a list of size 9. How do we know whether the list is palindrome or not.
constraints:
- we donot know list length.
- donot use temporary memory(array or stack or another list) for whole list or half of list. usage of few temp chars is acceptable.
- list modification is okay, as long as we have original list by end of operation.
I’ve few solutions in mind, thought of discussing with everyone. And it is single linked list.
Thanks & Rgds,
~calvin
my solution: take fast and slow ptrs, reverse half of the list and compare with another half. And reverse the reversed half so that list will look like original. I’m looking for better solution.
edit: since i couldn’t find any better sol.