Interview Shuriken 46: Is Palindrome

This problem was asked in Snapdeal, Microsoft and Amazon.

Given a singly linked list, you have to find out whether it is a palindrome or not. For example, if the given linked list is 1 -> 2 -> 3 -> 2 -> 1 -> null, then the output should be true.

Follow up: Try doing it in O(n) time complexity, here, n is the number of nodes in the linked list and O(1) space complexity.

Input Format:
The first and only line of input contains space separated integers,
 terminated by -1. These integers form data of nodes of linked list.
Output Format:
The first and only line of output contains true, if the linked list
 is palindrome or false, if the linked list is not palindrome. 
Sample Input 1 :
9 2 3 3 2 9 -1
Sample Output 1 :
true
Sample Input 2 :
0 2 3 2 5 -1
Sample Output 2 :
false

Comments

Popular posts from this blog

Access and modify all the resources of our Wiki.js using WikiJS API

MySQL Multi Source Master Slave Replication using GTID

How to pass parameters in webhook?