Stealth Interview
  • Features
  • Pricing
  • Blog
  • Login
  • Sign up

How to Solve Palindrome Linked List on LeetCode

The Palindrome Linked List problem is a linked list challenge involving reversal and pointer techniques.

Leetcode

Problem Statement

Given the head of a singly linked list, return true if it is a palindrome.

Example:

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

Why This Problem Matters for Interviews

  • Combines multiple linked list patterns (find middle, reverse, compare)
  • Appears often as a medium-difficulty question
  • Tests memory optimization and pointer skills

Approach to Palindrome Linked List

Find Middle, Reverse Second Half, Compare

  1. Use fast/slow pointers to find the list's middle.
  2. Reverse the second half.
  3. Compare both halves.

Time Complexity: O(n)
Space Complexity: O(1)

def isPalindrome(head): # Find middle slow = fast = head while fast and fast.next: slow = slow.next fast = fast.next.next # Reverse second half prev = None while slow: slow.next, prev, slow = prev, slow, slow.next # Compare halves left, right = head, prev while right: if left.val != right.val: return False left, right = left.next, right.next return True

Key Interview Talking Points

  • Why O(1) space is possible (no extra array)
  • Steps to reverse linked list in-place
  • How to handle odd/even length lists

Big O Complexity Recap

ApproachTime ComplexitySpace Complexity
Reverse Second Half, CompareO(n)O(1)

Pro Interview Tips

  • Draw lists for both odd and even cases
  • Remember to restore the list if needed
  • Explain all steps clearly

Ace your next coding interview

We're here to help you ace your next coding interview.

Subscribe
Stealth Interview
© 2025 Stealth Interview ™All rights reserved.
Product
  • Blog
  • Pricing
Company
  • Terms of Service
  • Privacy Policy