Skip to interview prep
Apexed

53. Palindrome Linked List

MediumLinked lists

Return true if the values of the linked list read the same forwards and backwards. Try O(1) extra space.

A linked list is passed as ListNode objects with val and next. The tests write lists as arrays.

Example 1

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

Constraints

  • 1 ≤ nodes ≤ 10⁵

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Palindrome Linked List — coding interview practice — Apexed