Check a Linked List of Reaction Codes Reads the Same Backward

Last updated: November 29, 2026

Quick Overview

Given the head of a singly linked list of reaction codes, return True if the sequence is a palindrome, using O(n) time and O(1) extra space.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given the head of a singly linked list of reaction codes, return True if the sequence is a palindrome, using O(n) time and O(1) extra space.

A common Meta phone-screen Easy that tests whether you can combine fast/slow pointers with in-place reversal, framed as checking whether a reaction sequence on a post is symmetric. The interviewer often accepts the array copy first, then asks for O(1) space and whether you restore the list.

What the Interviewer Expects
  • Offer the simple copy-to-array solution and its O(n) space
  • Find the middle with fast and slow pointers
  • Reverse the second half in place and compare
  • Restore the list before returning
  • Handle odd and even lengths
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 recursively and explain the hidden stack usage.
  • What if the list is doubly linked?
  • Return the length of the longest palindromic prefix instead.
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 integers (possibly empty). Output: True if the values read the same forwards and backwards. Target O(n) time and O(1) extra space, and the caller should get the ...

High-Level Design

Move slow one step and fast two steps; when fast reaches the end, slow is at the start of the second half (for odd length, skip the exact middle by advancing slow once more). Reverse from `slo...


Submit Your Answer
Markdown supported