Palindrome Linked List with Restoration
Updated
Problem statement
Given the head of a non-empty singly linked list, determine whether its values form a palindrome while using constant auxiliary space for the comparison.
Reverse the second half in place, compare the two halves, and restore the list before returning. Return an integer array whose first value is 1 when the list is a palindrome and 0 otherwise; the remaining values must be the restored list from head to tail.
Function
checkAndRestorePalindrome(head: ListNode) → int[]Examples
Example 1
head = [1,2,2,1]return = [1,1,2,2,1]The values are palindromic, and the returned suffix proves that the original order was restored.
Example 2
head = [1,2,3]return = [0,1,2,3]The end values differ, but the list still appears in its original order after the check.
Constraints
- The list contains at least one node.
- Every node value is a signed integer.
- The list is acyclic.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Remove Nth Node From End of ListDruva · ONSITE INTERVIEW
- Find the Entry of a Linked List CycleQualys · ONSITE INTERVIEWQualys interview questions
- Detect a Linked-List CyclePaytm · ONSITE INTERVIEWPaytm interview questions
- Detect a Linked-List CycleCapgemini · ONSITE INTERVIEWCapgemini interview questions
- Rearrange a Linked List from Alternating EndsConcentric AI · ONSITE INTERVIEWConcentric AI interview questions
- Linked List Cycle Entry NodeGoogle · ONSITE INTERVIEWGoogle interview questions
- Detect and Break a Linked-List CycleAmazon · ONSITE INTERVIEW
- Odd-Even Linked ListBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Find the Entry of a Linked List CyclePeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
- Remove a Cycle from a Singly Linked ListExpedia · ONSITE INTERVIEWExpedia interview questions