DSA Tracker

Problem

Pattern this teaches:Fast and Slow Pointers

Easy

Palindrome Linked List

An easy Linked List interview guide. Task statement, worked examples, intuition, and step-by-step solutions.

Topic
Linked List
Sheets
3
Core for
4 roles

The problem

Given the head of a linked list, determine whether it is a palindrome.

Example 1

Input
[1,3,3,1]
Output
true

Example 2

Input
[2,5,5,3,2]
Output
false

Example 3

Input
[1]
Output
true

Constraints

  • 0 <= n <= 10^5
  • -10^5 <= Node.val <= 10^5

How to think about it

Updated 2026-09-29

Symmetry demands comparing outermost pairs toward the center, but singly linked lists cannot be navigated in reverse. Halving the list and reversing only the rear half creates two independent chains that can be traversed forward side-by-side to compare values.

Approaches, worst first

  1. Copy to array buffer

    time O(n) · space O(n)

    Extract all values into an array list, then check palindrome properties using standard two pointers converging from both boundaries. Trivial to write, but allocates heap memory proportional to the list size.

  2. Split, reverse second half, and compareWrite this one

    time O(n) · space O(1)

    Find the midpoint using fast and slow pointers, reverse the list starting after the midpoint, and compare node values sequentially against the front half. Optionally restore the second half before returning to avoid mutating caller data.

Where people lose marks · 3
  • Forgetting to terminate the front half before the reversed second half causes comparison loops to overshoot on odd-length lists.
  • Comparing node references instead of node values tests whether instances are identical rather than checking if values mirror symmetrically.
  • An empty list or single-node list must return true without triggering null dereferences during midpoint splitting.

The theory behind it

Linked List — the ground this problem stands on. All Linked List problems

What Linked List is

A linked list is a chain of separate cargo cars connected by coupling hooks, scattered anywhere across memory rather than sitting in a tidy contiguous row. Each car, called a node, holds a single piece of data and a pointer directing traffic to the address of the next car in line. Because nodes connect only by directional links, jumping straight to the tenth car is impossible without walking past the first nine.

When to reach for it

Choose a linked list when a problem requires frequent insertions and deletions at known positions without shifting whole blocks of surrounding memory. Problems mentioning pointer splicing, reversing subsequences in place, merging sorted streams, or detecting cycles in linear chains strongly point here. It is ideal when total capacity is unpredictable and memory allocation must happen one individual node at a time.

How the pattern works

Think in terms of pointer rewiring before dereferencing. Keep a dummy head node pointing to the start of the list so modifications to the initial item do not require separate edge logic. Always save references to neighboring nodes into temporary variables before cutting or redirecting forward links. When diagnosing loops or locating middle nodes, advance two references simultaneously at differing velocities so traversal completes without supplementary storage.

More Linked List problems

Track in your role's order

Pick your target role and all 370 problems resequence to what that interview actually asks.

Start free

Problem set and role mapping as of .