By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
"This problem appears in 1 out of every 3 Linked List interviews—master it, and you’ll prove you can break down complex constraints into clean, efficient code under pressure."
Before tackling this problem, ensure you’re comfortable with: 1. Linked List Traversal – Iterating, reversing, and splitting lists. 2. Two-Pointer Techniques – Fast/slow pointers for cycle detection and midpoint finding. 3. In-Place Reversal – Modifying a linked list without extra space.
fast = fast.next.next; slow = slow.next
slow
prev = None; curr = head; while curr: next = curr.next; curr.next = prev; ...
left = head; right = reversed_half; while right: if left.val != right.val → False
Mental Checklist for Every Palindrome Linked List Problem:
If head is None or head.next is None, return True (empty or single-node lists are palindromes).
head
None
head.next
True
Find the Middle
fast moves 2 steps, slow moves 1 step → slow ends at the middle.
fast
Reverse the Second Half
slow.next
Example: 1→2→3→2→1 → Reverse 3→2→1 to 1→2→3.
1→2→3→2→1
3→2→1
1→2→3
Compare Halves
If all values match → True; else → False.
False
Restore the List (Optional)
If the problem requires preserving the original list, reverse the second half again.
Time & Space Complexity
O(n)
O(1)
Problem: Given a singly linked list, determine if it’s a palindrome.
Solution (Python):
class ListNode: def __init__(self, val=0, next=None): self.val = val self.next = next def isPalindrome(head: ListNode) -> bool: # Step 1: Edge cases if not head or not head.next: return True # Step 2: Find middle (slow) slow, fast = head, head while fast and fast.next: slow = slow.next fast = fast.next.next # Step 3: Reverse second half prev = None while slow: next_node = slow.next slow.next = prev prev = slow slow = next_node # Step 4: Compare halves left, right = head, prev while right: if left.val != right.val: return False left = left.next right = right.next return True
Why This Works: - Fast & Slow Pointers efficiently find the midpoint. - In-Place Reversal avoids extra space. - Two-Pointer Comparison checks symmetry in O(n) time.
Complexity: - Time: O(n) (3 passes: find middle, reverse, compare). - Space: O(1) (no extra data structures).
Problem: Check if a linked list is a palindrome without modifying the original list.
def isPalindromePreserve(head: ListNode) -> bool: # Step 1: Edge cases if not head or not head.next: return True # Step 2: Find middle (slow) slow, fast = head, head while fast and fast.next: slow = slow.next fast = fast.next.next # Step 3: Reverse second half (but restore later) prev = None curr = slow while curr: next_node = curr.next curr.next = prev prev = curr curr = next_node # Step 4: Compare halves left, right = head, prev is_palindrome = True while right: if left.val != right.val: is_palindrome = False break left = left.next right = right.next # Step 5: Restore the list curr = prev prev = None while curr: next_node = curr.next curr.next = prev prev = curr curr = next_node return is_palindrome
Why This Works: - Reverses and restores the second half to avoid permanent modification. - Same time complexity (O(n)), but extra pass to restore the list.
Complexity: - Time: O(n) (4 passes: find middle, reverse, compare, restore). - Space: O(1) (still in-place).
Problem: Solve the problem recursively (less common, but asked in some interviews).
def isPalindromeRecursive(head: ListNode) -> bool: # Use a helper to track the left node self.left = head def helper(right): if not right: return True # Recurse to the end is_pal = helper(right.next) # Compare left and right if not is_pal: return False if self.left.val != right.val: return False self.left = self.left.next return True return helper(head)
Why This Works: - Recursion reaches the end of the list, then compares nodes on the way back. - Space: O(n) (call stack), but no extra data structures.
Complexity: - Time: O(n) (traversal + comparison). - Space: O(n) (recursion stack).
if not head or not head.next: return True
next
next_node
curr.next
"Alright, let’s lock this in. Here’s your 60-second recap before the interview:
If they ask for recursion, know it’s O(n) space. If they ask for preservation, reverse twice. And if they ask for optimization, stick to the two-pointer approach. You’ve got this!
1→2→2→1
1→2→3→4
1
Now go crush that interview! ?
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.