{"id":5051,"date":"2021-09-20T10:11:04","date_gmt":"2021-09-20T10:11:04","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=5051"},"modified":"2022-03-10T19:34:22","modified_gmt":"2022-03-10T19:34:22","slug":"length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/","title":{"rendered":"Length of longest palindrome list in a linked list using O(1) extra space"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png\" alt=\"\" \/><\/p>\n<h3>Introduction<\/h3>\n<p>The linked list is one of the most important concepts and data structures to learn while preparing for interviews. Having a good grasp of Linked Lists can be a huge plus point in a coding interview.<\/p>\n<\/p>\n<h3>Problem Statement<\/h3>\n<p>According to the problem statement, our task is to find the length of the longest palindrome list in a linked list. <\/p>\n<h3>Problem Statement Understanding<\/h3>\n<p>We have been given a linked list. We have to find the length of the longest palindrome list in the given linked list. <\/p>\n<p>Let\u2019s understand this problem with the help of examples.<\/p>\n<p>If the input given linked list is: head\u219213\u21922\u21926\u21921\u21926\u21922\u219211\u21926.<\/p>\n<ul>\n<li>In the above given linked list, the sublist  2\u21926\u21921\u21926\u21922 is a palindrome, and also it is the longest palindrome in the list.<\/li>\n<li>As the length of 2\u21926\u21921\u21926\u21922 is 5, so our output will be 5.<\/li>\n<\/ul>\n<p>Let\u2019s take another example if the input list is: head\u21929\u21927\u21929\u219211\u21925\u21927\u21924\u21924\u21927.<\/p>\n<ul>\n<li>In this example, there are two sublists that are palindrome, one is 9\u21927\u21929, and another is 7\u21924\u21924\u21927. But we have to print the length of the longest palindrome list, and that is 4.<\/li>\n<\/ul>\n<h5>Some more examples<\/h5>\n<p>Sample Input 1: 1\u21922\u21923\u21923\u21922\u21927<br \/>\nSample Output 1: 4<\/p>\n<p>Sample Input 2: 3\u21926\u21929\u21924\u21927\u21927\u21924\u21929\u21926\u219211<br \/>\nSample Output 2:  8<\/p>\n<p>Now I think from the above examples, the problem statement is clear. So let&#8217;s see how we will approach it.<\/p>\n<p>Before moving to the approach section, try to think about how you can approach this problem. <\/p>\n<ul>\n<li>If stuck, no problem, we will thoroughly see how we can approach the problem in the next section.<\/li>\n<\/ul>\n<p>Let\u2019s move to the approach section.<\/p>\n<h3>Approach<\/h3>\n<p>The first thing that we need to focus on is that a palindrome is a sequence that reads the same backward and forwards. <\/p>\n<ul>\n<li>\n<p>Let\u2019s say if we have a sequence \u201cabcba\u201d and we want to check whether it is a palindromic sequence or not. So, for a sequence to be a palindromic sequence, it should follow the property that when we reverse the first half of the sequence, then the first half should become the same as the second half of the sequence.<\/p>\n<\/li>\n<li>\n<p>\u201cabcba\u201d is an odd-length palindromic sequence. So, when we reverse the first two characters of the sequence, i.e., ab to ba, then it becomes the same as the last two characters of the sequence, i.e. ba.<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_1-14.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_2-15.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_3-8.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_4-4.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_5-1.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_6-1.png\" alt=\"\" \/><\/p>\n<h3>Algorithm<\/h3>\n<ul>\n<li>Start traversing through the linked list.<\/li>\n<li>Declare pointers <strong>curr<\/strong> and <strong>prv<\/strong> of type Node.<\/li>\n<li>Initialize <strong>curr<\/strong> with head and <strong>prv<\/strong> with NULL.<\/li>\n<li><strong>curr<\/strong> points to the current node of the linked list.<\/li>\n<li>In every step, the linked list from <strong>head<\/strong> to <strong>curr<\/strong> is reversed, and <strong>prv<\/strong> points to this reversed linked list.<\/li>\n<li>For every current node, We will call function <strong>countCommon()<\/strong>. This function will return the number of common elements in the two linked lists.<\/li>\n<li>We will call this function two times to check for odd length palindrome and even length palindrome.\n<ul>\n<li>In the case of odd length palindrome, our answer will be (2* No. of common elements )+1.<\/li>\n<li>In the case of even length palindrome, our answer will be (2* No. of common elements).<\/li>\n<\/ul>\n<\/li>\n<li>When we call <strong>countCommon()<\/strong> function, in the case of odd length palindrome, we will exclude the <strong>current node<\/strong> and, in the case of even length palindrome, we will include the <strong>current node<\/strong>.\n<ul>\n<li>We are including and excluding current node in the above step because we have to care about the length of the palindrome linked list.<\/li>\n<li>It is already known that in odd length palindrome, the middle element doesn\u2019t have any match. Ex. \u201caba\u201d here aba is a palindrome but \u2018b\u2019 doesn\u2019t have any match. <\/li>\n<\/ul>\n<\/li>\n<li>Store the length of longest palindrome sublist in a variable named <strong>result<\/strong>.<\/li>\n<li>Update <strong>result<\/strong>, whenever we found a sublist having length greater than the value of the result.<\/li>\n<\/ul>\n<h3>Dry Run<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_7-1.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_8-1.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_9.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_10.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_11.png\" alt=\"\" \/><br \/>\n<img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/p_12.png\" alt=\"\" \/><\/p>\n<h3>Code Implementation<\/h3>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_5053 {\r\n\toverflow:hidden;\r\n\tdisplay:block;\r\n\twidth:100%;\r\n\tborder:0px solid #ddd;\r\n\tmargin-bottom:30px;\r\n\t}\r\n\r\n#tab_container_5053 .tab-content{\r\n\tpadding:20px;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n\tmargin-top: 0px;\r\n\tbackground-color:#ffffff !important;\r\n\tcolor: #000000 !important;\r\n\tfont-size:16px !important;\r\n\tfont-family: Open Sans !important;\r\n\t\r\n\t\tborder: 1px solid #e6e6e6 !important;\r\n\t}\r\n#tab_container_5053 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_5053 .wpsm_nav-tabs > li.active > a, #tab_container_5053 .wpsm_nav-tabs > li.active > a:hover, #tab_container_5053 .wpsm_nav-tabs > li.active > a:focus {\r\n\tcolor: #000000 !important;\r\n\tcursor: default;\r\n\tbackground-color: #ffffff !important;\r\n\tborder: 1px solid #e6e6e6 !important;\r\n}\r\n\r\n#tab_container_5053 .wpsm_nav-tabs > li > a {\r\n    margin-right: 0px !important; \r\n    line-height: 1.42857143 !important;\r\n    border: 1px solid #d5d5d5 !important;\r\n    border-radius: 0px 0px 0 0 !important; \r\n\tbackground-color: #e8e8e8 !important;\r\n\tcolor: #000000 !important;\r\n\tpadding: 15px 18px 15px 18px !important;\r\n\ttext-decoration: none !important;\r\n\tfont-size: 14px !important;\r\n\ttext-align:center !important;\r\n\tfont-family: Open Sans !important;\r\n}\r\n#tab_container_5053 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_5053 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_5053 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_5053 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_5053 .wpsm_nav-tabs > li > a:hover , #tab_container_5053 .wpsm_nav-tabs > li > a:focus {\r\n    color: #000000 !important;\r\n    background-color: #e8e8e8 !important;\r\n\tborder: 1px solid #d5d5d5 !important;\r\n\t\r\n}\r\n#tab_container_5053 .wpsm_nav-tabs > li > a .fa{\r\n\r\nmargin-right:5px !important;\r\n\r\nmargin-left:5px !important;\r\n\r\n\r\n}\r\n\r\n\t\t#tab_container_5053 .wpsm_nav-tabs a{\r\n\t\t\tbackground-image: none;\r\n\t\t\tbackground-position: 0 0;\r\n\t\t\tbackground-repeat: repeat-x;\r\n\t\t}\r\n\t\t\t\r\n\r\n\r\n#tab_container_5053 .wpsm_nav-tabs > li {\r\n    float: left;\r\n    margin-bottom: -1px !important;\r\n\tmargin-right:0px !important; \r\n}\r\n\r\n\r\n#tab_container_5053 .tab-content{\r\noverflow:hidden !important;\r\n}\r\n\r\n\r\n@media (min-width: 769px) {\r\n\r\n\t#tab_container_5053 .wpsm_nav-tabs > li{\r\n\t\tfloat:left !important ;\r\n\t\t\t\tmargin-right:-1px !important;\r\n\t\t\t\t\t}\r\n\t#tab_container_5053 .wpsm_nav-tabs{\r\n\t\tfloat:none !important;\r\n\t\tmargin:0px !important;\r\n\t}\r\n\r\n\t#tab_container_5053 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5053 .wpsm_nav{\r\n\t\t\t}\r\n\r\n}\r\n\r\n\r\n\r\n@media (max-width: 768px) {\r\n\t#tab_container_5053 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_5053 .wpsm_nav{\r\n\t\t\t}\r\n}\r\n\r\n\r\n\t.wpsm_nav-tabs li:before{\r\n\t\tdisplay:none !important;\r\n\t}\r\n\r\n\t@media (max-width: 768px) {\r\n\t\t\t\t\r\n\t\t\t\t.wpsm_nav-tabs{\r\n\t\t\tmargin-left:0px !important;\r\n\t\t\tmargin-right:0px !important; \r\n\t\t\t\r\n\t\t}\r\n\t\t\t\t#tab_container_5053 .wpsm_nav-tabs > li{\r\n\t\t\tfloat:none !important;\r\n\t\t}\r\n\t\t\t\r\n\t}\t\t\t\t<\/style>\r\n\t\t\t\t<div id=\"tab_container_5053\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_5053\">\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  class=\"active\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5053_1\" aria-controls=\"tabs_desc_5053_1\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5053_2\" aria-controls=\"tabs_desc_5053_2\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>C++<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5053_3\" aria-controls=\"tabs_desc_5053_3\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Java<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t<li role=\"presentation\"  onclick=\"do_resize()\">\r\n\t\t\t\t\t\t\t\t<a href=\"#tabs_desc_5053_4\" aria-controls=\"tabs_desc_5053_4\" role=\"tab\" data-toggle=\"tab\">\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<i class=\"fa fa-code\"><\/i> \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t<span>Python<\/span>\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t<\/a>\r\n\t\t\t\t\t\t\t<\/li>\r\n\t\t\t\t\t\t\t\t\t\t\t <\/ul>\r\n\r\n\t\t\t\t\t  <!-- Tab panes -->\r\n\t\t\t\t\t  <div class=\"tab-content\" id=\"tab-content_5053\">\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane  in active \" id=\"tabs_desc_5053_1\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"C\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"C\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include&lt;stdio.h&gt;\r\n#include&lt;stdlib.h&gt;\r\n\r\n#define max(x, y) (((x) &gt; (y)) ? (x) : (y))\r\n#define min(x, y) (((x) &lt; (y)) ? (x) : (y))\r\nstruct Node\r\n{\r\n    int data;\r\n    struct Node* next;\r\n};\r\n \r\n\/\/ function for counting the common elements\r\nint countCommon(struct Node *a,struct Node *b)\r\n{\r\n    int count = 0;\r\n \r\n    \/\/ loop to count common in the list starting\r\n    \/\/ from node a and b\r\n    for (; a &amp;&amp; b; a = a-&gt;next, b = b-&gt;next)\r\n \r\n        \/\/ increment the count for same values\r\n        if (a-&gt;data == b-&gt;data)\r\n            ++count;\r\n        else\r\n            break;\r\n \r\n    return count;\r\n}\r\n \r\n\/\/ Returns length of the longest palindrome\r\n\/\/ sublist in given list\r\nint maxPalindrome(struct Node *head)\r\n{\r\n    int result = 0;\r\n    struct Node *prev = NULL;\r\n    struct Node *curr = head;\r\n \r\n    \/\/ loop till the end of the linked list\r\n    while (curr)\r\n    {\r\n        \/\/ The sublist from head to current\r\n        \/\/ reversed.\r\n        struct Node *next = curr-&gt;next;\r\n        curr-&gt;next = prev;\r\n \r\n        \/\/ check for odd length palindrome\r\n        \/\/ by finding longest common list elements\r\n        \/\/ beginning from prev and from next (We\r\n        \/\/ exclude curr)\r\n        result = max(result,\r\n                     2*countCommon(prev, next)+1);\r\n \r\n        \/\/ check for even length palindrome\r\n        \/\/ by finding longest common list elements\r\n        \/\/ beginning from curr and from next\r\n        result = max(result,\r\n                     2*countCommon(curr, next));\r\n \r\n        \/\/ update prev and curr for next iteration\r\n        prev = curr;\r\n        curr = next;\r\n    }\r\n    return result;\r\n}\r\n \r\n\/\/ Utility function to create a new list node\r\nstruct Node *newNode(int key)\r\n{\r\n    struct Node* temp = (struct Node*)malloc(sizeof(struct Node));\r\n    temp-&gt;data = key;\r\n    temp-&gt;next = NULL;\r\n    return temp;\r\n}\r\n \r\n\/* Driver program to test above functions*\/\r\nint main()\r\n{\r\n    \/* Let us create a linked lists to test\r\n       the functions\r\n    Created list is a: 2-&gt;4-&gt;3-&gt;4-&gt;2-&gt;15 *\/\r\n    struct Node *head = newNode(2);\r\n    head-&gt;next = newNode(4);\r\n    head-&gt;next-&gt;next = newNode(3);\r\n    head-&gt;next-&gt;next-&gt;next = newNode(4);\r\n    head-&gt;next-&gt;next-&gt;next-&gt;next = newNode(2);\r\n    head-&gt;next-&gt;next-&gt;next-&gt;next-&gt;next = newNode(15);\r\n \r\n\tint ans = maxPalindrome(head);\r\n    printf(&quot;%d &#92;n&quot;,ans);\r\n    return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5053_2\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"cpp\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n#include&lt;bits stdc++.h=&quot;&quot;&gt;\r\nusing namespace std;\r\n \r\n\/* Node structure of the linked list node *\/\r\nclass Node{\r\npublic:\r\n  int data;\r\n  Node* next;\r\n};\r\n \r\n\/* Using this function we will be counting the number of common elements in the given two linked lists *\/\r\nint countCommon(Node *a, Node *b){\r\n  int count = 0;\r\n \r\n  for (; (a!=NULL &amp;&amp; b!=NULL); a = a-&gt;next, b = b-&gt;next)\r\n \r\n    if (a-&gt;data == b-&gt;data){\r\n      ++count;\r\n    }\r\n    else{\r\n      break;\r\n    }\r\n    \r\n  return count;\r\n}\r\n \r\n\/* Using this function we will be finding the length of the longest palindrome sublist in the given linked list *\/\r\nint maxPalindrome(Node *head){\r\n  int result = 0;\r\n  Node *prev = NULL, *curr = head;\r\n \r\n  while (curr){\r\n    Node *next = curr-&gt;next;\r\n    curr-&gt;next = prev;\r\n \r\n    result = max(result,\r\n          2*countCommon(prev, next)+1);\r\n\r\n    result = max(result,\r\n          2*countCommon(curr, next));\r\n \r\n    prev = curr;\r\n    curr = next;\r\n  }\r\n  return result;\r\n}\r\n \r\n\/* Using this function we will be creating a new list node *\/\r\nNode *newNode(int key){\r\n  Node *temp = new Node;\r\n  temp-&gt;data = key;\r\n  temp-&gt;next = NULL;\r\n  return temp;\r\n}\r\n \r\n \r\nint main(){\r\n  Node *head = newNode(11);\r\n  head-&gt;next = newNode(12);\r\n  head-&gt;next-&gt;next = newNode(4);\r\n  head-&gt;next-&gt;next-&gt;next = newNode(12);\r\n  head-&gt;next-&gt;next-&gt;next-&gt;next = newNode(9);\r\n  head-&gt;next-&gt;next-&gt;next-&gt;next-&gt;next = newNode(11);\r\n \r\n  cout&lt;&lt;&quot;Length of longest palindrome list is: &quot;;\r\n  cout &lt;&lt; maxPalindrome(head) &lt;&lt; endl;\r\n  return 0;\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\r\n\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5053_3\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"Java\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\nclass LargestPalindrome\r\n{\r\n    static class Node\r\n    {\r\n\t    int data;\r\n\t    Node next;\r\n    }\r\n    static int countCommon(Node a, Node b)\r\n    {\r\n\t    int count = 0;\r\n\t    for (; a != null &amp;&amp; b != null;\r\n\t\t\ta = a.next, b = b.next)\r\n\r\n\t\tif (a.data == b.data)\r\n\t\t\t++count;\r\n\t\telse\r\n\t\t\tbreak;\r\n\r\n\t    return count;\r\n    }\r\n    static int maxPalindrome(Node head)\r\n    {\r\n\t    int result = 0;\r\n\t    Node prev = null, curr = head;\r\n\r\n\t    while (curr != null)\r\n\t    {\r\n\t\t    \/\/ The sublist from head to current reversed\r\n\t\t    Node next = curr.next;\r\n\t\t    curr.next = prev;\r\n\r\n\t\t\/* check for odd length palindrome by finding longest common list elements\r\n\t\t beginning from prev and from next (We exclude curr) *\/\r\n\t\tresult = Math.max(result,2 * countCommon(prev, next)+1);\r\n\r\n\t\t\/* check for even length palindrome by finding longest common list elements\r\n\t\t beginning from curr and from next *\/\r\n\t\tresult = Math.max(result,2*countCommon(curr, next));\r\n\r\n\t\t\/\/ update prev and curr for next iteration\r\n\t\tprev = curr;\r\n\t\tcurr = next;\r\n\t    }\r\n\t    return result;\r\n    }\r\n    static Node newNode(int key)\r\n    {\r\n\t    Node temp = new Node();\r\n\t    temp.data = key;\r\n\t    temp.next = null;\r\n\t    return temp;\r\n    }\r\n    \/* Driver code*\/\r\n    public static void main(String[] args)\r\n    {\r\n\t    Node head = newNode(2);\r\n\t    head.next = newNode(4);\r\n\t    head.next.next = newNode(3);\r\n\t    head.next.next.next = newNode(4);\r\n\t    head.next.next.next.next = newNode(2);\r\n\t    head.next.next.next.next.next = newNode(15);\r\n\r\n\t    System.out.println(maxPalindrome(head));\r\n    }\r\n}\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\t\t\t\t\t <div role=\"tabpanel\" class=\"tab-pane \" id=\"tabs_desc_5053_4\">\r\n\t\t\t\t\t\t\t\t<!-- wp:enlighter\/codeblock {\"language\":\"python\"} -->\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\r\n# Linked List node\r\nclass Node:\r\n\tdef __init__(self, data):\r\n\t\tself.data = data\r\n\t\tself.next = None\r\n\r\n# function for counting the common elements\r\ndef countCommon(a, b) :\r\n\r\n\tcount = 0\r\n\r\n\twhile ( a != None and b != None ) :\r\n\r\n\t\tif (a.data == b.data) :\r\n\t\t\tcount = count + 1\r\n\t\telse:\r\n\t\t\tbreak\r\n\t\t\r\n\t\ta = a.next\r\n\t\tb = b.next\r\n\r\n\treturn count\r\n\r\n# Returns length of the longest palindrome\r\n# sublist in given list\r\ndef maxPalindrome(head) :\r\n\r\n\tresult = 0\r\n\tprev = None\r\n\tcurr = head\r\n\twhile (curr != None) :\r\n\t\r\n\t\tnext = curr.next\r\n\t\tcurr.next = prev\r\n\t\tresult = max(result, 2 * countCommon(prev, next) + 1)\r\n\t\tresult = max(result, 2 * countCommon(curr, next))\r\n\t\tprev = curr\r\n\t\tcurr = next\r\n\t\r\n\treturn result\r\n\r\n# Utility function to create a new list node\r\ndef newNode(key) :\r\n\r\n\ttemp = Node(0)\r\n\ttemp.data = key\r\n\ttemp.next = None\r\n\treturn temp\r\n\r\nhead = newNode(11)\r\nhead.next = newNode(12)\r\nhead.next.next = newNode(4)\r\nhead.next.next.next = newNode(12)\r\nhead.next.next.next.next = newNode(9)\r\nhead.next.next.next.next.next = newNode(11)\r\n\r\nprint(&quot;Length of longest palindrome list is:&quot;, maxPalindrome(head))\r\n\r\n<\/pre>\r\n<!-- \/wp:enlighter\/codeblock -->\t\t\t\t\t\t <\/div>\r\n\t\t\t\t\t\t\t\r\n\t\t\t\t\t <\/div>\r\n\t\t\t\t\t \r\n\t\t\t\t <\/div>\r\n <script>\r\n\t\tjQuery(function () {\r\n\t\t\tjQuery('#myTab_5053 a:first').tab('show')\r\n\t\t});\r\n\t\t\r\n\t\t\t\tjQuery(function(){\r\n\t\t\tvar b=\"fadeIn\";\r\n\t\t\tvar c;\r\n\t\t\tvar a;\r\n\t\t\td(jQuery(\"#myTab_5053 a\"),jQuery(\"#tab-content_5053\"));function d(e,f,g){\r\n\t\t\t\te.click(function(i){\r\n\t\t\t\t\ti.preventDefault();\r\n\t\t\t\t\tjQuery(this).tab(\"show\");\r\n\t\t\t\t\tvar h=jQuery(this).data(\"easein\");\r\n\t\t\t\t\tif(c){c.removeClass(a);}\r\n\t\t\t\t\tif(h){f.find(\"div.active\").addClass(\"animated \"+h);a=h;}\r\n\t\t\t\t\telse{if(g){f.find(\"div.active\").addClass(\"animated \"+g);a=g;}else{f.find(\"div.active\").addClass(\"animated \"+b);a=b;}}c=f.find(\"div.active\");\r\n\t\t\t\t});\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\r\n\t\tfunction do_resize(){\r\n\r\n\t\t\tvar width=jQuery( '.tab-content .tab-pane iframe' ).width();\r\n\t\t\tvar height=jQuery( '.tab-content .tab-pane iframe' ).height();\r\n\r\n\t\t\tvar toggleSize = true;\r\n\t\t\tjQuery('iframe').animate({\r\n\t\t\t    width: toggleSize ? width : 640,\r\n\t\t\t    height: toggleSize ? height : 360\r\n\t\t\t  }, 250);\r\n\r\n\t\t\t  toggleSize = !toggleSize;\r\n\t\t}\r\n\r\n\r\n\t<\/script>\r\n\t\t\t\t\r\n\t\t\t\n<h4>Output<\/h4>\n<p>Length of longest palindrome list is: 3<\/p>\n<p><strong>Time Complexity:<\/strong> O(N<sup>2<\/sup>), For every node of the linked list, We have traversed through the remaining part of the linked list for comparison of the common elements.<\/p>\n<p>[forminator_quiz id=&#8221;5052&#8243;]<\/p>\n<p>So, In this blog, we have learned how to find the length of the longest palindrome list in a linked list. This is a basic problem and is good for strengthening your concepts in LinkedList and if you want to practice more such problems, you can checkout <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">Prepbytes (Linked List)<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The linked list is one of the most important concepts and data structures to learn while preparing for interviews. Having a good grasp of Linked Lists can be a huge plus point in a coding interview. Problem Statement According to the problem statement, our task is to find the length of the longest palindrome [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-5051","post","type-post","status-publish","format-standard","hentry","category-linked-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Length of longest palindrome list in a linked list using O(1) extra space | Linked list articles | PrepBytes Blog<\/title>\n<meta name=\"description\" content=\"Learn the most efficient way to the length of the longest palindrome list in a linked list using O(1) extra space.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Length of longest palindrome list in a linked list using O(1) extra space | Linked list articles | PrepBytes Blog\" \/>\n<meta property=\"og:description\" content=\"Learn the most efficient way to the length of the longest palindrome list in a linked list using O(1) extra space.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/\" \/>\n<meta property=\"og:site_name\" content=\"PrepBytes Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prepbytes0211\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-20T10:11:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-10T19:34:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png\" \/>\n<meta name=\"author\" content=\"PrepBytes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"PrepBytes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Length of longest palindrome list in a linked list using O(1) extra space\",\"datePublished\":\"2021-09-20T10:11:04+00:00\",\"dateModified\":\"2022-03-10T19:34:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/\"},\"wordCount\":718,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/\",\"name\":\"Length of longest palindrome list in a linked list using O(1) extra space | Linked list articles | PrepBytes Blog\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png\",\"datePublished\":\"2021-09-20T10:11:04+00:00\",\"dateModified\":\"2022-03-10T19:34:22+00:00\",\"description\":\"Learn the most efficient way to the length of the longest palindrome list in a linked list using O(1) extra space.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/43.205.93.38\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linked list articles\",\"item\":\"https:\/\/prepbytes.com\/blog\/category\/linked-list\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Length of longest palindrome list in a linked list using O(1) extra space\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/43.205.93.38\/#website\",\"url\":\"http:\/\/43.205.93.38\/\",\"name\":\"PrepBytes Blog\",\"description\":\"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING\",\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/43.205.93.38\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/43.205.93.38\/#organization\",\"name\":\"Prepbytes\",\"url\":\"http:\/\/43.205.93.38\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"contentUrl\":\"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp\",\"width\":160,\"height\":160,\"caption\":\"Prepbytes\"},\"image\":{\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/prepbytes0211\/\",\"https:\/\/www.instagram.com\/prepbytes\/\",\"https:\/\/www.linkedin.com\/company\/prepbytes\/\",\"https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\",\"name\":\"PrepBytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g\",\"caption\":\"PrepBytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Length of longest palindrome list in a linked list using O(1) extra space | Linked list articles | PrepBytes Blog","description":"Learn the most efficient way to the length of the longest palindrome list in a linked list using O(1) extra space.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/","og_locale":"en_US","og_type":"article","og_title":"Length of longest palindrome list in a linked list using O(1) extra space | Linked list articles | PrepBytes Blog","og_description":"Learn the most efficient way to the length of the longest palindrome list in a linked list using O(1) extra space.","og_url":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-09-20T10:11:04+00:00","article_modified_time":"2022-03-10T19:34:22+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Length of longest palindrome list in a linked list using O(1) extra space","datePublished":"2021-09-20T10:11:04+00:00","dateModified":"2022-03-10T19:34:22+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/"},"wordCount":718,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/","url":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/","name":"Length of longest palindrome list in a linked list using O(1) extra space | Linked list articles | PrepBytes Blog","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png","datePublished":"2021-09-20T10:11:04+00:00","dateModified":"2022-03-10T19:34:22+00:00","description":"Learn the most efficient way to the length of the longest palindrome list in a linked list using O(1) extra space.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645007260291-Article_151.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/length-of-longest-palindrome-list-in-a-linked-list-using-o1-extra-space\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/43.205.93.38\/"},{"@type":"ListItem","position":2,"name":"Linked list articles","item":"https:\/\/prepbytes.com\/blog\/category\/linked-list\/"},{"@type":"ListItem","position":3,"name":"Length of longest palindrome list in a linked list using O(1) extra space"}]},{"@type":"WebSite","@id":"http:\/\/43.205.93.38\/#website","url":"http:\/\/43.205.93.38\/","name":"PrepBytes Blog","description":"ONE-STOP RESOURCE FOR EVERYTHING RELATED TO CODING","publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/43.205.93.38\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/43.205.93.38\/#organization","name":"Prepbytes","url":"http:\/\/43.205.93.38\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/","url":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","contentUrl":"https:\/\/blog.prepbytes.com\/wp-content\/uploads\/2025\/07\/uzxxllgloialmn9mhwfe.webp","width":160,"height":160,"caption":"Prepbytes"},"image":{"@id":"http:\/\/43.205.93.38\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/prepbytes0211\/","https:\/\/www.instagram.com\/prepbytes\/","https:\/\/www.linkedin.com\/company\/prepbytes\/","https:\/\/www.youtube.com\/channel\/UC0xGnHDrjUM1pDEK2Ka5imA"]},{"@type":"Person","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e","name":"PrepBytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/850669d326db1e1531f04db0c63145d941c2a26792aaeee226a9e6675b0ac698?s=96&d=mm&r=g","caption":"PrepBytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/prepbytes\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5051","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=5051"}],"version-history":[{"count":6,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5051\/revisions"}],"predecessor-version":[{"id":7964,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/5051\/revisions\/7964"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=5051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=5051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=5051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}