38. Palindrome Linked List

38. Palindrome Linked List

Easy
58.0%
1.9k
linked-liststacktwo-pointers
Google, Amazon, Netflix, Meta (Facebook), Apple, Microsoft, Uber, Bloomberg, Airbnb, Stripe, Adobe, Salesforce, LinkedIn, Oracle

You’re interviewing for a backend or data engineering role at a FAANG-level company. The interviewer describes a real product scenario:

A large-scale backend system processes ordered data streams stored as singly linked lists. In certain workflows such as data validation, fraud detection, or consistency checks, the system needs to verify whether a sequence of values reads the same forward and backward.

Because the data is stored in a linked list rather than an array, random access is not available. The platform expects an efficient solution that checks whether the list forms a palindrome without unnecessary memory usage.

This is a common practice coding problem for DSA question might ask in Google, Amazon, Netflix, Meta, Apple, Microsoft, Uber, and Bloomberg interviews.

Your Task

Given the head of a singly linked list, return true if the linked list is a palindrome, or false otherwise.

A linked list is a palindrome if the sequence of node values reads the same forward and backward.

Input Format

  • head: the head node of a singly linked list

Each node is defined as:

ListNode { int val; ListNode next; }

Output Format

  • A boolean value
    • true if the linked list is a palindrome
    • false otherwise

Examples

Example 1:

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

Example 2:

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

Example 3:

Input: head = [1]
Output: true

Constraints

  • 0 <= number of nodes <= 100,000
  • -10^9 <= Node.val <= 10^9

Loading editor...

[1,2,2,1]
true

Console Output

Click "Run Code" or "Submit" to see results

Your code will be evaluated by AI with instant feedback