Linked ListFast and Slow PointersPointer Reversal
Decide whether the values of a singly linked list read the same forwards and backwards. Aim for O(1) extra space. The values are given as an array; build the linked list from them yourself, then solve it with pointers.
Input
Line 1: n. Line 2: the n node values from head to tail.
Output
Print true if the list is a palindrome, otherwise false.
Constraints
1 <= n <= 10^5 0 <= value <= 9
Example 1
Input
4 1 2 2 1
Output
true
Reads 1 2 2 1 in both directions.
Example 2
Input
2 1 2
Output
false
1 2 reversed is 2 1.