Learner Level
Implement the palindromeLinkedListCheck method that checks whether the linked list values form a palindrome.
The linked list is provided as an integer array nodes, where each value represents one node from head to tail.
Your task is to check whether the linked list is a palindrome. A linked list is a palindrome when the values read the same from the beginning and from the end.
For example, [1,2,2,1] is a palindrome, but [1,2] is not because the first and last values are different.
Compare the list values from both ends.
Use one pointer at the first element and another pointer at the last element. If both values are equal, move the left pointer forward and the right pointer backward. If any pair does not match, the linked list cannot be a palindrome.
If all opposite pairs match until the pointers meet or cross, return true.
Pseudocode:
function palindromeLinkedListCheck(nodes, size):
left = 0
right = size - 1
while left < right:
if nodes[left] != nodes[right]:
return false
left++
right--
return true