Check whether a linked list is a palindrome
Coding problemEasy-MediumAsked in: Accolite, Adobe, Amazon, MakeMyTrip, Microsoft, Snapdeal
Given the head of a linked list of integers, return true if the values read the same from front to back as from back to front, and false otherwise.
An empty list and a single node both count as palindromes. Try to use only a constant amount of extra memory.
Examples
Example 1
Input: head = [1,2,2,1]
Output: true
Example 2
Input: head = [1,2]
Output: false
Example 3
Input: head = [3,0,3]
Output: true
Constraints
- The list has between 0 and 100,000 nodes
- Each value is between -1,000,000,000 and 1,000,000,000
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.