Coders Crushby Napplied AI
Back to DSA Problems
EasyLinked Lists

Palindrome Linked List

Check if linked list is palindrome

Solution Approach

Find middle with slow/fast pointers, reverse second half, then compare both halves.

Implementation
def isPalindromeList(head):
    if not head or not head.next:
        return True
    
    # Find middle
    slow = fast = head
    while fast and fast.next:
        slow = slow.next
        fast = fast.next.next
    
    # Reverse second half
    prev = None
    while slow:
        next_node = slow.next
        slow.next = prev
        prev = slow
        slow = next_node
    
    # Compare
    left, right = head, prev
    while right:  # right will be shorter
        if left.val != right.val:
            return False
        left = left.next
        right = right.next
    return True
Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(1)
Complexity
Time:O(n)
Space:O(1)
Asked at
GoogleFacebook
Coders Crushby Napplied AI

The ultimate interview preparation platform. Master System Design, DSA, and tackle community challenges to crush your FAANG interviews.

Looking for jobs? Visit Napplied AI Jobs Search Agent

System Design

  • All Problems
  • Easy
  • Hard

DSA

  • All Problems
  • Dynamic Programming
  • Graphs

More

  • Problems Arena
  • Growth Paths
  • My Crush

Coders Crush by Napplied AI - Tech Interview & Coding Should Be Effortless