'Coding has over 700 languages', '67% of programming jobs aren’t in the technology industry', 'Coding is behind almost everything that is powered by electricity'
Topics

Check If Linked List Is Palindrome

Easy
0/40
Average time to solve is 15m
profile
Contributed by
53 upvotes
Asked in companies
CiscoGoogleCognizant

Problem statement

You are given a Singly Linked List of integers. You have to return true if the linked list is palindrome, else return false.


A Linked List is a palindrome if it reads the same from left to right and from right to left.


Example:
The lists (1 -> 2 -> 1), (3 -> 4 -> 4-> 3), and (1) are palindromes, while the lists (1 -> 2 -> 3) and (3 -> 4) are not.
Detailed explanation ( Input/output format, Notes, Images )
Sample Input 1:
1 2 2 1 -1
Sample Output 1:
True
Explanation for Sample Input 1:
The given list is a palindrome.
Sample Input 2:
3 2 1 -1
Sample Output 2:
False
Constraints :
1 <= 'N' <= 5 * 10^4
-10^9 <= 'data' <= 10^9 and 'data' != -1

Where 'N' is the number of nodes in the linked list and ‘data’ represents the value of the list's nodes.

Time Limit: 1sec
Full screen
Console