Skip to content
Decoder

Palindrome Linked List

Easy

Problem

Given the head of a singly linked list, return True if its values read the same forwards and backwards, and False otherwise. Can you do it in O(n) time and O(1) extra space?

Example 1

Input
1
Output
2 -> 2 -> 1 → True

Example 2

Input
1
Output
2 -> 3 -> 2 -> 1 → True

Example 3

Input
1
Output
2 → False

Constraints

  • 1 <= number of nodes <= 10^5
  • 0 <= Node.val <= 9

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.