{"id":4092,"date":"2021-08-20T07:25:49","date_gmt":"2021-08-20T07:25:49","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=4092"},"modified":"2023-11-27T04:58:18","modified_gmt":"2023-11-27T04:58:18","slug":"rotate-a-linked-list","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/","title":{"rendered":"Rotate a Linked List"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png\" alt=\"\" \/><br \/>\nManipulating linked lists is a core aspect of data structures and algorithms in programming. Rotating a linked list involves rearranging its elements by shifting nodes to a specified number of positions. Understanding how to perform this operation is crucial for various applications, such as in optimizing memory usage or solving specific programming problems efficiently. This article aims to explore the concept of rotating a linked list, delve into different approaches for rotation, and provide insights into the algorithms and techniques involved in accomplishing this task.<\/p>\n<h2>How to Rotate a Linked List?<\/h2>\n<p>In this question, we are given a singly linked list and an integer X. We have to rotate the list counter-clockwise by X nodes.<\/p>\n<p>Note: X is smaller than the count of nodes in the linked list.<\/p>\n<p>Let\u2019s try to understand the problem statement with the help of an example.<\/p>\n<p>Suppose the given linked list 1 \u2192 2 \u2192 5 \u2192 10 &#8211; 12 \u2192 13, and the value of X is 4. Now, we have to rotate the given list counter-clockwise by X. <\/p>\n<p>Here, rotating counter-clockwise a linked list by X means that the first X nodes of the linked list will be removed from the start and get appended to the end of the list.<\/p>\n<p>In the given list, the first 4 nodes are 1 \u2192 2 \u2192 5 \u2192 10. Now, these 4 elements will get appended to the end of the list. So, the final list will be:<br \/>\n12 \u2192 13 \u2192 1 \u2192 2 \u2192 5 \u2192 10.<\/p>\n<p>In this way, we are rotating the given first X nodes counter-clockwise. <\/p>\n<p><strong>Input :<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/input-7.png\" alt=\"\" \/><\/p>\n<p><strong>Output :<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/output-2.png\" alt=\"\" \/><\/p>\n<p><strong>Explanation :<\/strong> As the value of X is 4, so the first 4 nodes have been removed from the beginning of the linked list and appended at the end of the linked list.<\/p>\n<p>Now, I think from the above example, it is clear what we have to do in this problem. So let\u2019s move to approach.<\/p>\n<p>Before directly jumping to approach in the next section, just try to think how will approach this problem?<\/p>\n<p>It\u2019s okay if your solution is not the best-optimized solution, we will try to optimize it together.<\/p>\n<p>This question is not a very complex one. We are going to make use of linked list traversal in this question. Let us have a glance at the approach.<\/p>\n<h2>Approach and Algorithm of rotate a linked list<\/h2>\n<p>The approach is going to be pretty simple.<br \/>\nLet us first think about what we need to perform the required task of rotating the list counter-clockwise by X nodes.<\/p>\n<ul>\n<li>For linked list rotation, we have to change the next of X<sup>th<\/sup> node to NULL, next of the last node to the head node, and finally, make the head point to the (X+1)<sup>th<\/sup> node.<\/li>\n<li>So, we need X<sup>th<\/sup> node, (X+1)<sup>th<\/sup> node and the last node.<\/li>\n<\/ul>\n<p>To acheive the above objective of rotation:<\/p>\n<ul>\n<li>We will traverse through the list and stop at the X<sup>th<\/sup> node.<\/li>\n<li>We will store the pointer to the X<sup>th<\/sup> node.<\/li>\n<li>The (X+1)<sup>th<\/sup> node can be reached using the next of X<sup>th<\/sup> node. Now, we will keep traversing the list till the last node, and change the pointers as stated below:\n<ul>\n<li>Change the next of X<sup>th<\/sup> node to NULL<\/li>\n<li>Next of the last node to the head node.<\/li>\n<li>And finally, make the head point to the (X+1)<sup>th<\/sup> node.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Dry Run of rotate a linked list<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Rotate-a-Linked-List-1.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/08\/Rotate-a-Linked-List-2.png\" alt=\"\" \/><\/p>\n<h2>Code Implementation of rotate a linked list<\/h2>\n\t\t\t\t\t\t<style>\r\n\t\t\t\t\r\n\t\t\t\t\t#tab_container_4093 {\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_4093 .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_4093 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_4093 .wpsm_nav-tabs > li.active > a, #tab_container_4093 .wpsm_nav-tabs > li.active > a:hover, #tab_container_4093 .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_4093 .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_4093 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_4093 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_4093 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_4093 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_4093 .wpsm_nav-tabs > li > a:hover , #tab_container_4093 .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_4093 .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_4093 .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_4093 .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_4093 .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_4093 .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_4093 .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_4093 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4093 .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_4093 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4093 .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_4093 .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_4093\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_4093\">\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_4093_1\" aria-controls=\"tabs_desc_4093_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_4093_2\" aria-controls=\"tabs_desc_4093_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_4093_3\" aria-controls=\"tabs_desc_4093_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_4093_4\" aria-controls=\"tabs_desc_4093_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_4093\">\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_4093_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\r\n#include &lt;stdio.h&gt;\r\n#include &lt;stdlib.h&gt;\r\n \r\n\/* Link list node *\/\r\nstruct Node {\r\n    int data;\r\n    struct Node* next;\r\n};\r\n \r\nvoid rotate(struct Node** head_ref, int k)\r\n{\r\n    if (k == 0)\r\n        return;\r\n \r\n    struct Node* current = *head_ref;\r\n \r\n    int count = 1;\r\n    while (count &lt; k &amp;&amp; current != NULL) {\r\n        current = current-&gt;next;\r\n        count++;\r\n    }\r\n \r\n    if (current == NULL)\r\n        return;\r\n \r\n    struct Node* kthNode = current;\r\n \r\n    while (current-&gt;next != NULL)\r\n        current = current-&gt;next;\r\n \r\n    current-&gt;next = *head_ref;\r\n \r\n    *head_ref = kthNode-&gt;next;\r\n \r\n    kthNode-&gt;next = NULL;\r\n}\r\n \r\nvoid push(struct Node** head_ref, int new_data)\r\n{\r\n    \/* allocate node *\/\r\n    struct Node* new_node = (struct Node*)malloc(sizeof(struct Node));\r\n \r\n    \/* put in the data  *\/\r\n    new_node-&gt;data = new_data;\r\n \r\n    \/* link the old list off the new node *\/\r\n    new_node-&gt;next = (*head_ref);\r\n \r\n    \/* move the head to point to the new node *\/\r\n    (*head_ref) = new_node;\r\n}\r\n \r\nvoid printList(struct Node* node)\r\n{\r\n    while (node != NULL) {\r\n        printf(&quot;%d &quot;, node-&gt;data);\r\n        node = node-&gt;next;\r\n    }\r\n}\r\nint main(void)\r\n{\r\n    struct Node* head = NULL;\r\n \r\n    for (int i = 60; i &gt; 0; i -= 10)\r\n        push(&amp;head, i);\r\n \r\n    printf(&quot;Given linked list &#92;n&quot;);\r\n    printList(head);\r\n    rotate(&amp;head, 4);\r\n \r\n    printf(&quot;&#92;nRotated Linked list &#92;n&quot;);\r\n    printList(head);\r\n \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_4093_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\nclass Node {\r\npublic:\r\n    int data;\r\n    Node* next;\r\n};\r\n\r\nvoid rotate(Node** head_ref, int k)\r\n{\r\n    if (k == 0)\r\n        return;\r\n\r\n    Node* current = *head_ref;\r\n\r\n    int count = 1;\r\n    while (count &lt; k &amp;&amp; current != NULL) {\r\n        current = current-&gt;next;\r\n        count++;\r\n    }\r\n\r\n    if (current == NULL)\r\n        return;\r\n\r\n    Node* kthNode = current;\r\n\r\n    while (current-&gt;next != NULL)\r\n        current = current-&gt;next;\r\n \r\n    current-&gt;next = *head_ref;\r\n\r\n    *head_ref = kthNode-&gt;next;\r\n\r\n    kthNode-&gt;next = NULL;\r\n}\r\n\r\nvoid push(Node** head_ref, int new_data)\r\n{\r\n\r\n    Node* new_node = new Node();\r\n\r\n    new_node-&gt;data = new_data;\r\n\r\n    new_node-&gt;next = (*head_ref);\r\n\r\n    (*head_ref) = new_node;\r\n}\r\n\r\nvoid printList(Node* node)\r\n{\r\n    while (node != NULL) {\r\n        cout &lt;&lt; node-&gt;data &lt;&lt; &quot; &quot;;\r\n        node = node-&gt;next;\r\n    }\r\n}\r\n\r\nint main(void)\r\n{\r\n\r\n    Node* head = NULL;\r\n\r\n       push(&amp;head, 13);\r\n       push(&amp;head,12);\r\n       push(&amp;head,10);\r\n       push(&amp;head,5);\r\n       push(&amp;head,2);\r\n       push(&amp;head,1);\r\n     \r\n \r\n    cout &lt;&lt; &quot;Given linked list &#92;n&quot;;\r\n    printList(head);\r\n    rotate(&amp;head, 4);\r\n \r\n    cout &lt;&lt; &quot;&#92;nRotated Linked list &#92;n&quot;;\r\n    printList(head);\r\n \r\n    return (0);\r\n}\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_4093_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\npublic class LinkedList {\r\n    Node head; \r\n    \r\n    class Node {\r\n        int data;\r\n        Node next;\r\n        Node(int d)\r\n        {\r\n            data = d;\r\n            next = null;\r\n        }\r\n    }\r\n\r\n    void rotate(int k)\r\n    {\r\n        if (k == 0)\r\n            return;\r\n\r\n        Node current = head;\r\n\r\n        int count = 1;\r\n        while (count &lt; k &amp;&amp; current != null) {\r\n            current = current.next;\r\n            count++;\r\n        }\r\n\r\n        if (current == null)\r\n            return;\r\n\r\n        Node kthNode = current;\r\n\r\n        while (current.next != null)\r\n            current = current.next;\r\n\r\n\r\n        current.next = head;\r\n\r\n        head = kthNode.next;\r\n\r\n        kthNode.next = null;\r\n    }\r\n\r\n    void push(int new_data)\r\n    {\r\n\r\n        Node new_node = new Node(new_data);\r\n\r\n        new_node.next = head;\r\n\r\n        head = new_node;\r\n    }\r\n\r\n    void printList()\r\n    {\r\n        Node temp = head;\r\n        while (temp != null) {\r\n            System.out.print(temp.data + &quot; &quot;);\r\n            temp = temp.next;\r\n        }\r\n        System.out.println();\r\n    }\r\n\r\n    public static void main(String args[])\r\n    {\r\n        LinkedList llist = new LinkedList();\r\n\r\n        \r\n            llist.push(13);\r\n            llist.push(12);\r\n            llist.push(10);\r\n            llist.push(5);\r\n            llist.push(2);\r\n            llist.push(1);\r\n            \r\n\r\n        System.out.println(&quot;Given list&quot;);\r\n        llist.printList();\r\n\r\n        llist.rotate(4);\r\n\r\n        System.out.println(&quot;Rotated Linked List&quot;);\r\n        llist.printList();\r\n    }\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_4093_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\nclass Node:\r\n\r\n\tdef __init__(self, data):\r\n\t\tself.data = data\r\n\t\tself.next = None\r\n\r\nclass LinkedList:\r\n\r\n\tdef __init__(self):\r\n\t\tself.head = None\r\n\r\n\tdef push(self, new_data):\r\n\r\n\t\tnew_node = Node(new_data)\r\n\t\tnew_node.next = self.head\r\n\t\tself.head = new_node\r\n\r\n\tdef printList(self):\r\n\t\ttemp = self.head\r\n\t\twhile(temp):\r\n\t\t\tprint(temp.data, end=&quot; &quot;)\r\n\t\t\ttemp = temp.next\r\n\r\n\tdef rotate(self, k):\r\n\t\tif k == 0:\r\n\t\t\treturn\r\n\t\t\r\n\t\tcurrent = self.head\r\n\t\tcount = 1\r\n\r\n\t\twhile(count &lt;k and current is not None):\r\n\t\t\tcurrent = current.next\r\n\t\t\tcount += 1\r\n\r\n\t\tif current is None:\r\n\t\t\treturn\r\n\r\n\t\tkthNode = current\r\n\t\r\n\t\twhile(current.next is not None):\r\n\t\t\tcurrent = current.next\r\n\r\n\t\tcurrent.next = self.head\r\n\t\tself.head = kthNode.next\r\n\t\tkthNode.next = None\r\n\r\n\r\n\r\nllist = LinkedList()\r\n\r\nllist.push(13)\r\nllist.push(12)\r\nllist.push(10)\r\nllist.push(5)\r\nllist.push(2)\r\nllist.push(1)\r\n\r\nprint(&quot;Given linked list&quot;)\r\nllist.printList()\r\nllist.rotate(4)\r\n\r\nprint(&quot;&#92;nRotated Linked list&quot;)\r\nllist.printList()\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_4093 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_4093 a\"),jQuery(\"#tab-content_4093\"));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<pre><code>Output\nGiven linked list: 1 2 5 10 12 13\nRotated Linked list: 12 13 1 2 5 10 <\/code><\/pre>\n<p><strong>Time Complexity rotate a linked list:<\/strong> O(n), as list traversal is needed.<\/p>\n<p><strong>Conclusion<\/strong><br \/>\nRotating a linked list is a fundamental operation that finds utility in various programming scenarios. The methods and algorithms discussed in this article offer diverse approaches to efficiently perform rotations, catering to different requirements and complexities. Understanding these techniques equips programmers with valuable tools to manipulate linked lists effectively, facilitating optimized solutions for problems that demand reordering elements within these data structures. Mastering linked list rotation is not only essential for algorithmic problem-solving but also for enhancing one&#8217;s proficiency in data structure manipulation and algorithm design.<\/p>\n<p>By comprehending the nuances of linked list rotation and employing the appropriate algorithms, developers can optimize code efficiency, streamline solutions, and harness the full potential of linked lists in programming applications.<\/p>\n<h2>FAQs related to Rotate Linked list<\/h2>\n<p>Here are some FAQs related to Rotate Linked List.<\/p>\n<p><strong>1. What does rotating a linked list mean?<\/strong><br \/>\nRotating a linked list involves repositioning its elements by moving nodes a specified number of places either to the left or right. It essentially changes the order of the elements in the list while maintaining its structure.<\/p>\n<p><strong>2. How is the rotation direction determined in a linked list?<\/strong><br \/>\nThe direction of rotation in a linked list, whether left or right, depends on the problem statement or the desired outcome. For instance, rotating a list left means moving nodes from the beginning to the end, while a right rotation involves moving nodes from the end to the beginning.<\/p>\n<p><strong>3. What are the different approaches to rotate a linked list?<\/strong><br \/>\n<strong>Iterative Method:<\/strong> Involves traversing the list to find the new head and tail nodes after rotation.<br \/>\n<strong>Using k-th Node:<\/strong> Identifying the k-th node from the beginning and making it the new head after rotation.<br \/>\n<strong>Reversal Technique:<\/strong> Combining reversal and node manipulation to achieve rotation efficiently.<\/p>\n<p><strong>4. How efficient are the rotation algorithms for large linked lists?<\/strong><br \/>\nThe efficiency of rotation algorithms depends on the approach used. Some techniques might involve traversing the list multiple times, impacting performance for large lists. However, certain methods like using the k-th node or the reversal technique can offer better efficiency in terms of time complexity.<\/p>\n<p><strong>5. Are there any considerations while implementing linked list rotation?<\/strong><br \/>\nIt&#8217;s essential to handle edge cases such as empty lists, rotations beyond the list length, or handling rotations when the number of positions is greater than the list size. Additionally, maintaining the pointers correctly during rotation to avoid memory leaks or dangling pointers is crucial.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Manipulating linked lists is a core aspect of data structures and algorithms in programming. Rotating a linked list involves rearranging its elements by shifting nodes to a specified number of positions. Understanding how to perform this operation is crucial for various applications, such as in optimizing memory usage or solving specific programming problems efficiently. This [&hellip;]<\/p>\n","protected":false},"author":52,"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-4092","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>Learn the easy approach to Rotate a Linked List in C++ and JAVA<\/title>\n<meta name=\"description\" content=\"Learn the most efficient way to rotate a linked list. This article explains the most efficient approach to rotate a linked list.\" \/>\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\/rotate-a-linked-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn the easy approach to Rotate a Linked List in C++ and JAVA\" \/>\n<meta property=\"og:description\" content=\"Learn the most efficient way to rotate a linked list. This article explains the most efficient approach to rotate a linked list.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/\" \/>\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-08-20T07:25:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-27T04:58:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/\"},\"author\":{\"name\":\"Prepbytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e\"},\"headline\":\"Rotate a Linked List\",\"datePublished\":\"2021-08-20T07:25:49+00:00\",\"dateModified\":\"2023-11-27T04:58:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/\"},\"wordCount\":964,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/\",\"name\":\"Learn the easy approach to Rotate a Linked List in C++ and JAVA\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png\",\"datePublished\":\"2021-08-20T07:25:49+00:00\",\"dateModified\":\"2023-11-27T04:58:18+00:00\",\"description\":\"Learn the most efficient way to rotate a linked list. This article explains the most efficient approach to rotate a linked list.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#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\":\"Rotate a Linked List\"}]},{\"@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\/3f7dc4ae851791d5947a7f99df363d5e\",\"name\":\"Prepbytes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g\",\"caption\":\"Prepbytes\"},\"url\":\"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn the easy approach to Rotate a Linked List in C++ and JAVA","description":"Learn the most efficient way to rotate a linked list. This article explains the most efficient approach to rotate a linked list.","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\/rotate-a-linked-list\/","og_locale":"en_US","og_type":"article","og_title":"Learn the easy approach to Rotate a Linked List in C++ and JAVA","og_description":"Learn the most efficient way to rotate a linked list. This article explains the most efficient approach to rotate a linked list.","og_url":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-08-20T07:25:49+00:00","article_modified_time":"2023-11-27T04:58:18+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png","type":"","width":"","height":""}],"author":"Prepbytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Prepbytes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/"},"author":{"name":"Prepbytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/3f7dc4ae851791d5947a7f99df363d5e"},"headline":"Rotate a Linked List","datePublished":"2021-08-20T07:25:49+00:00","dateModified":"2023-11-27T04:58:18+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/"},"wordCount":964,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/","url":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/","name":"Learn the easy approach to Rotate a Linked List in C++ and JAVA","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png","datePublished":"2021-08-20T07:25:49+00:00","dateModified":"2023-11-27T04:58:18+00:00","description":"Learn the most efficient way to rotate a linked list. This article explains the most efficient approach to rotate a linked list.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1644926056999-108.Rotate%20a%20Linked%20List_Artboard%203.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/rotate-a-linked-list\/#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":"Rotate a Linked List"}]},{"@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\/3f7dc4ae851791d5947a7f99df363d5e","name":"Prepbytes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/232042cd1a1ea0e982c96d2a2ec93fb70a8e864e00784491231e7bfe5a9e06b5?s=96&d=mm&r=g","caption":"Prepbytes"},"url":"https:\/\/prepbytes.com\/blog\/author\/gourav-jaincollegedekho-com\/"}]}},"_links":{"self":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4092","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\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/comments?post=4092"}],"version-history":[{"count":8,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4092\/revisions"}],"predecessor-version":[{"id":18381,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4092\/revisions\/18381"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=4092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=4092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=4092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}