2Brute2Best
🔥0

Palindrome Linked List

Easy·LeetCode #234 Pro OnlyBasic Reinforcement
LeetCode
01

Problem Statement

You are given the head of a singly linked list. Return true if the values read the same forwards and backwards (a palindrome), and false otherwise.

Follow-up: can you do it in O(N) time and O(1) extra space?

Input

head, the first node of a singly linked list.

Output

true if the list's values form a palindrome, otherwise false.

Example 1
Input: head = [1, 2, 2, 1]
Output: true

Read backwards it is still 1, 2, 2, 1.

Example 2
Input: head = [1, 2]
Output: false

Backwards it is 2, 1, which is different.

Constraints
  • • The list has between 1 and 10^5 nodes.
  • • 0 ≤ Node.val ≤ 9
  • • Follow-up: O(N) time and O(1) extra space.
02

Pattern Recognition Clues

Recognising these key signals in the problem description immediately identifies the pattern:

“palindrome”
→ Compare the front with the back → split the list into two halves at the middle.
“singly linked list”
→ Can't walk backwards → reverse the back half so it can be walked forwards from the tail.
“O(1) extra space”
→ No copying into a vector or stack → find the middle with slow/fast and relink in place.
03

Approach Complexity Ladder

Brute Force — copy values to an arrayO(N)O(N)

Copy values into a vector, compare from both ends

Optimal — find the middle, reverse the second half, compare, restoreO(N)O(1)

Slow/fast to the middle, reverse the back half in place, compare, reverse it back

Brute Force Intuition

The trouble with a linked list is that we can't walk it backwards. An array doesn't have that problem. Copy all values into a vector, then use two pointers: one at the start, one at the end, moving inward and comparing.

Recognition rule for this sub-pattern:

When fast reaches the end, slow is in the middle. Use this to split a list in half.
Remember this · Linked List — Fast & Slow
Trigger
Cycle detection, middle of list, "n-th from end", two lists meeting, repeating sequences.
Think
If one pointer moves faster or starts earlier, where will they meet?
Key question
What speed or gap makes the meeting point tell me the answer?
Brute2Best Pro Content

Unlock Complete Visual Walkthrough & Optimal C++

The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.

All 440 visual dry runs & algorithms
Interactive step-by-step playback with pointer & array state transitions
52 comprehensive LLD chapters
Interactive UML diagrams, real-world stories (Food Delivery, Trading, RPG), and practice solutions
40 C++ basics labs & hardware memory models
Vtables, byte layouts, assembly insights, and multi-threading race conditions
Production-ready C++23 source code
Modern idioms, clean contracts, time/space complexity derivations, and interview takeaways

First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.

Beyond The LeetCode Problem

How this concept connects to System Design & C++ Systems

Bridge DSA with production engineering

Top engineering interviews test whether you understand how algorithms like Linked List — Fast & Slow translate into production architectures and low-level memory mechanics.