Geeksforgeeks

Error

Given a singly linked list of size **N** of integers. The task is to check if the given linked list is palindrome or not.

**Example 1:**

**Input:
**N = 3
value[] = {1,2,1}
**Output: **1**
Explanation: **The given linked list is
1 2 1 , which is a palindrome and
Hence, the output is 1.

**Example 2:**

**Input:
**N = 4
value[] = {1,2,3,4}
**Output: **0**
Explanation: **The given linked list
is 1 2 3 4 , which is not a palindrome
and Hence, the output is 0.

**Your Task:**

The task is to complete the function **isPalindrome**() which takes head as reference as the only parameter and returns true or false if linked list is palindrome or not respectively.

**Expected Time Complexity**: O(N)

**Expected Auxialliary Space Usage**: O(1) (ie, you should not use the recursive stack space as well)

**Constraints:**

1 <= N <= 10^{5}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Check if Linked List is Palindrome

...