Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Linked List Palindrome Check

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Linked List Palindrome Check. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

A Wisconsin.gov service workflow stores an ordered sequence of processing codes in a singly linked list. Write a function that determines whether the sequence reads identically from the beginning and the end.

Use constant auxiliary space by finding the midpoint with slow and fast pointers, reversing the second half in place, and comparing both halves. The input list may be modified during processing.

Formal Specification

The function receives head, either None or a reference to the first ListNode. Each node has an integer value field and a next field that references the next node or None. Return True if the linked-list values form a palindrome; otherwise, return False.

For even-length lists, split the list into two equal halves. For odd-length lists, ignore the middle node when comparing the two sides.

Constraints

  • 0 <= n <= 10^5
  • -10^9 <= node.value <= 10^9
  • The input is a singly linked list
  • The list may be modified during processing

Function Signature

def is_palindrome(head):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output