Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Check if a linked list is a palindrome

Determine whether a singly linked list reads the same forwards and backwards.

Python practice18 minLinked ListsIntermediateLast updated March 27, 2026

Problem statement

Given a singly linked list (input provided as a Python list of values), determine whether it is a palindrome. You should construct the linked list, then check palindrome by finding the midpoint, reversing the second half in-place, and comparing nodes. Restore the list if you wish (not required). Return True if the list is a palindrome, False otherwise. Edge cases: empty list and single-node list are palindromes.

Task

Given a list as a Python list, build a linked list, and check if it is a palindrome in O(n) time and O(1) extra linked-list pointer space (excluding input/output lists).

Examples

Odd-length palindrome

Input

[1, 2, 3, 2, 1]

Output

True

The sequence reads the same forwards and backwards.

Input format

A single Python list representing node values of the linked list.

Output format

Boolean True/False indicating palindrome status.

Constraints

- Aim for O(n) time and O(1) additional linked-list pointers. Values are integers. List size can be zero.

Samples

Sample 1

Input

[1, 2, 2, 1]

Output

True

Even-length palindrome.