Standard Bar Linked List · Medium Problems of LL O(N) · O(1)
A secure gate reads a one-way access chain and must confirm the code is a palindrome before opening — but the controller is too small to hold a second copy of the code. The trick: split the chain at its middle, flip the rear half in place, and then compare the two halves node by node as they march in lockstep.
Input: An array head of node values representing the linked list.
Output: true when the list reads the same forwards and backwards, false otherwise.
1 <= list length <= 10^5-10^9 <= node value <= 10^9Input: {"head":[1,2,2,1]}
Output: true
Front half 1-2 matches the flipped rear half 2-1 station for station.
Input: {"head":[1,2]}
Output: false
The halves disagree at the very first comparison.