easyLinked ListPure DSA~16 min
Palindrome Playlist Check
A playlist is stored as a singly linked list of track IDs. Decide whether it reads the same forwards and backwards using only constant extra memory.
Problem
Given the head of a singly linked list, return true if the list is a palindrome. Aim for O(n) time and O(1) extra space.
Input
The head of a singly linked list of n nodes (0 ≤ n ≤ 10^5), integer values.
Output
A boolean — true if the values form a palindrome.
Constraints
- Target O(1) extra space (excluding the input list)
- 0 ≤ n ≤ 100,000
- Restoring the list after checking is a nice-to-have
Examples
Example 1
Input
1 → 2 → 2 → 1
Output
true
The sequence mirrors itself.
Example 2
Input
1 → 2 → 3
Output
false
Reversed it is 3 → 2 → 1, which differs.