Update appNew update is available. Click here to update.

Check If Linked List Is Palindrome

Contributed by
Vishal Modani
Last Updated: 23 Feb, 2023
Easy
yellow-spark
0/40
Avg time to solve 15 mins
Success Rate 85 %
Share
6 upvotes

Problem Statement

You are given a Singly Linked List of integers. You have to find if the given linked list is palindrome or not.

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

For 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 )
Constraints :
1 <= T <= 10
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 nodes of the list.

Time Limit: 1sec
Sample Input 1:
3
1 2 2 1 -1
8 9 9 -1
4 -1
Sample Output 1:
True
False
True
Explanation for Sample Input 1:
In the 1st test case, the given list is a palindrome.
In the 2nd test case, the given list is not a palindrome.
In the 3rd test case,  the given list is a palindrome.
Sample Input 2:
2
3 2 1 -1
1 1 1 -1
Sample Output 2:
False
True
Reset Code
Full screen
Autocomplete
copy-code
Console