`{"id":"ca9cad8f-bf60-4331-99e5-2efb02ba377c","name":"Palindrome Linkedlist ","description":"Given a singly linked list of Integers, determine it is a palindrome or not.\r\n","inputFormat":"1->2->3->4->3->2->1->null\r\n1->2->3->4->2->1->null\r\n","outputFormat":"true\r\nfalse\r\n","constraints":"0 &lt;= N &lt;= 10^6\r\n","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nclass ListNode\r\n{\r\npublic:\r\n int val = 0;\r\n ListNode *next = nullptr;\r\n\r\n ListNode(int val)\r\n {\r\n this->val = val;\r\n }\r\n};\r\n\r\nbool isPalindrome(ListNode *head)\r\n{\r\n return false;\r\n}\r\n\r\nint main()\r\n{\r\n int n;\r\n cin >> n;\r\n ListNode *dummy = new ListNode(-1);\r\n ListNode *prev = dummy;\r\n while (n-- > 0)\r\n {\r\n int val;\r\n cin >> val;\r\n prev->next = new ListNode(val);\r\n prev = prev->next;\r\n }\r\n\r\n cout << (boolalpha) << isPalindrome(dummy->next) << endl;\r\n\r\n return 0;\r\n}"},"java":{"code":"import java.util.*;\r\n\r\nclass Main {\r\n public static class ListNode {\r\n int val = 0;\r\n ListNode next = null;\r\n\r\n ListNode(int val) {\r\n this.val = val;\r\n }\r\n }\r\n\r\n public static boolean isPalindrome(ListNode head) {\r\n \r\n return true;\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n ListNode dummy = new ListNode(-1);\r\n ListNode prev = dummy;\r\n while (n-- > 0) {\r\n prev.next = new ListNode(scn.nextInt());\r\n prev = prev.next;\r\n }\r\n\r\n System.out.println(isPalindrome(dummy.next));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10\r\n5\r\n1\r\n4\r\n6\r\n9\r\n9\r\n6\r\n4\r\n1\r\n5\r\n","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/rP4zdxydE_0","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"1e4c8949-5890-4d15-be5b-6601c7e2029a","name":"Linked List For Intermediate","slug":"linked-list-for-intermediate-637","type":0},{"id":"a3fa7515-5fe4-4e61-a75d-e44619d541d2","name":"Palindrome Linkedlist ","slug":"palindrome-linkedlist","type":1}],"next":{"id":"6e03be20-1a6d-4e8f-96d1-3bf9abbbd021","name":"Palindrome Linkedlist MCQ","type":0,"slug":"palindrome-linkedlist-mcq"},"prev":{"id":"424f1074-af64-4d91-8586-c5c46d61eec0","name":"Remove Nth Node From End Of Linked List","type":3,"slug":"remove-nth-node-from-end-of-linked-list"}}}`

Given a singly linked list of Integers, determine it is a palindrome or not.

`{"id":"ca9cad8f-bf60-4331-99e5-2efb02ba377c","name":"Palindrome Linkedlist ","description":"Given a singly linked list of Integers, determine it is a palindrome or not.\r\n","inputFormat":"1->2->3->4->3->2->1->null\r\n1->2->3->4->2->1->null\r\n","outputFormat":"true\r\nfalse\r\n","constraints":"0 &lt;= N &lt;= 10^6\r\n","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\n\r\nclass ListNode\r\n{\r\npublic:\r\n int val = 0;\r\n ListNode *next = nullptr;\r\n\r\n ListNode(int val)\r\n {\r\n this->val = val;\r\n }\r\n};\r\n\r\nbool isPalindrome(ListNode *head)\r\n{\r\n return false;\r\n}\r\n\r\nint main()\r\n{\r\n int n;\r\n cin >> n;\r\n ListNode *dummy = new ListNode(-1);\r\n ListNode *prev = dummy;\r\n while (n-- > 0)\r\n {\r\n int val;\r\n cin >> val;\r\n prev->next = new ListNode(val);\r\n prev = prev->next;\r\n }\r\n\r\n cout << (boolalpha) << isPalindrome(dummy->next) << endl;\r\n\r\n return 0;\r\n}"},"java":{"code":"import java.util.*;\r\n\r\nclass Main {\r\n public static class ListNode {\r\n int val = 0;\r\n ListNode next = null;\r\n\r\n ListNode(int val) {\r\n this.val = val;\r\n }\r\n }\r\n\r\n public static boolean isPalindrome(ListNode head) {\r\n \r\n return true;\r\n }\r\n\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n ListNode dummy = new ListNode(-1);\r\n ListNode prev = dummy;\r\n while (n-- > 0) {\r\n prev.next = new ListNode(scn.nextInt());\r\n prev = prev.next;\r\n }\r\n\r\n System.out.println(isPalindrome(dummy.next));\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10\r\n5\r\n1\r\n4\r\n6\r\n9\r\n9\r\n6\r\n4\r\n1\r\n5\r\n","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/rP4zdxydE_0","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"1e4c8949-5890-4d15-be5b-6601c7e2029a","name":"Linked List For Intermediate","slug":"linked-list-for-intermediate-637","type":0},{"id":"a3fa7515-5fe4-4e61-a75d-e44619d541d2","name":"Palindrome Linkedlist ","slug":"palindrome-linkedlist","type":1}],"next":{"id":"6e03be20-1a6d-4e8f-96d1-3bf9abbbd021","name":"Palindrome Linkedlist MCQ","type":0,"slug":"palindrome-linkedlist-mcq"},"prev":{"id":"424f1074-af64-4d91-8586-c5c46d61eec0","name":"Remove Nth Node From End Of Linked List","type":3,"slug":"remove-nth-node-from-end-of-linked-list"}}}`

Editor

easy

Given a singly linked list of Integers, determine it is a palindrome or not.

0 <= N <= 10^6

Format

Input

1->2->3->4->3->2->1->null 1->2->3->4->2->1->null

true false

Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}10 5 1 4 6 9 9 6 4 1 5 ```

Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}true ```

Question Video

Discussions

Show Discussion

Related Resources