🔍 Doubly Linked List - Palindrome Check

Check if the doubly linked list reads the same forwards and backwards!

🎯 Problem: Is the Doubly Linked List a Palindrome?

Hi! I'm Teju 👋 We need to determine if a doubly linked list is a palindrome — meaning it reads the same from both ends.

Example: 1 ↔ 2 ↔ 3 ↔ 2 ↔ 1 → true
1 ↔ 2 ↔ 3 ↔ 4 → false

Input: N (number of nodes), followed by N values

Output: true or false

Advantage of doubly linked list: We can traverse from both ends easily!

⚙️ Efficient Algorithm Using Two Pointers

Since it's doubly linked, we can use two pointers: one starting from the head (left) and one from the tail (right).

Move them towards the center, comparing values at each step.

  1. Get head and tail pointers
  2. While left is before or at right:
    • If values don't match → return false
    • Move left forward, right backward
  3. If all pairs match → return true

🎮 Interactive Demo

Enter the number of nodes and values to build the list...

Empty List ↔ null

📋 Final Result