Check Whether a Linked List of Characters Reads the Same Backward

Last updated: November 29, 2026

Quick Overview

A short spoken query has been tokenized into a singly linked list of characters. Decide whether it is a palindrome using O(1) extra space, and leave the list as you found it.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


A short spoken query has been tokenized into a singly linked list of characters. Decide whether it is a palindrome using O(1) extra space, and leave the list as you found it.

Google uses this to combine three pointer moves in one problem: find the middle, reverse half, compare. The interviewer also cares that you restore the list, since callers like the Assistant pipeline may still hold a reference to it.

What the Interviewer Expects
  • Find the middle with slow and fast pointers
  • Reverse the second half in place
  • Compare the halves node by node
  • Restore the second half afterward
  • Handle odd and even lengths without separate code paths
Key Topics to Cover
linked list
fast and slow pointers
in-place reversal
palindrome
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Do it without modifying the list at all. What does it cost?
  • Ignore case and non-letter characters while checking.
  • Make it work on a doubly linked list in O(1) space without reversing.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: head of a singly linked list of single characters.
  • Output: True if the sequence equals its reverse.
  • O(1) extra space and the list must be unchanged on return....
High-Level Design

Run slow and fast pointers so slow stops at the end of the first half. Reverse the list after slow, walk the first half and reversed second half together comparing values, then reverse the second half...


Submit Your Answer
Markdown supported