how should i check palindrome in linked list in O(N) time complexity and O(1) space.
Palindrome in linked list
O(1) space solution can be done by reversing half the linked list.
This method takes O(n) time and O(1) extra space.
- Get the middle of the linked list.
- Reverse the second half of the linked list.
- Check if the first half and second half are identical.
- If both the halves are identical it means they are palindrome.
But here you have to consider the case and handle both odd and even length linked lists carefully. Take a sample case of both these type. Dry run and and check.
okay thank you… i will try this approach