Palindrome Linked List

easy

Given the head of a singly linked list, return true if the list reads the same forwards and backwards — a palindrome — and false otherwise.

A singly linked list only lets you walk forward: from any node you can reach node.next, but never the node before it. So the whole challenge is checking a back-to-front property using a structure that only moves front-to-back.

For example, 1 → 2 → 2 → 1 is a palindrome (the sequence [1,2,2,1] mirrors itself), while 1 → 2 is not.

Hints

A palindrome reads the same both ways — but a singly linked list only lets you read one way. What could you do so the values become readable from both ends?
If you had the values in an array, the check is a trivial two-pointer sweep from the ends inward. Is there a way to avoid the extra array?
Find the middle with slow/fast pointers, reverse the second half in place, then walk the two halves toward each other comparing values.

Common doubts

Yes. The middle node has no mirror partner, and gating the compare loop on the (shorter) reversed half naturally skips it.
Yes — any list of length 0 or 1 reads the same forwards and backwards, so it returns true.

Interview follow-ups

Yes — that is exactly the optimal approach: slow/fast to find the middle, reverse the second half in place, then compare the two halves without any extra array.
After comparing, reverse the second half a second time to restore the original next pointers before returning — still O(1) extra space.

Fun facts

  • The slow/fast pointer pair used to find the middle here is the same 'tortoise and hare' idea that detects cycles in a linked list — one technique, many problems.
  • Reversing a portion of a list in place is a building block that reappears in problems like reversing nodes in k-groups and reordering a list.

Asked at

AmazonMicrosoftGoogleAdobeMeta
Frequently Sometimes Occasionally
Example 1
Input: head = [1,2,2,1]
Output: true
Reading the values forward gives [1,2,2,1]; backward gives [1,2,2,1] — identical.
Example 2
Input: head = [1,2]
Output: false
Forward is [1,2], backward is [2,1] — they differ, so it is not a palindrome.
Constraints

- The number of nodes in the list is in the range [1, 10^5]. - 0 <= Node.val <= 9

Solve this problem →