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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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...