Skip to content

visual walkthrough

Palindrome Linked List

EasyFast & Slow + ReversalReported at: AmazonMetaMicrosoft+7

Combines finding the middle with reversing the second half.

Solve on LeetCode

The idea

A palindrome needs the first value compared with the last, but a singly linked list only goes forwards.

So turn the second half around: find the middle with slow and fast pointers, reverse from there, then walk inwards from both ends.

Complexity

approachtimespace
Copy to an arrayO(n)O(n)
Reverse the second halfO(n)O(1)

More walkthroughs