{"id":4867,"date":"2021-09-14T12:07:26","date_gmt":"2021-09-14T12:07:26","guid":{"rendered":"https:\/\/www.prepbytes.com\/blog\/?p=4867"},"modified":"2022-04-19T00:09:22","modified_gmt":"2022-04-19T00:09:22","slug":"find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space","status":"publish","type":"post","link":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/","title":{"rendered":"Find pair for given sum in a sorted singly linked without extra space"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.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 a linked list can be a huge plus point in coding interviews.<\/p>\n<\/p>\n<h3>Problem Statement<\/h3>\n<p>In this problem, we are given a sorted singly linked list and a value k, our task is to find the pairs whose sum is equal to K. <\/p>\n<p><strong>Note:<\/strong> we can consider a node in one pair only.<\/p>\n<p>Example:<\/p>\n<p>Input : head \u2192 0 \u2192 2 \u2192 3 \u2192 7 \u2192 8 \u2192 10 , K = 10.<\/p>\n<p>Output:<br \/>\n0 10<br \/>\n2  8<br \/>\n7  3<\/p>\n<h3>Problem Statement Understanding<\/h3>\n<p>Let\u2019s first understand the problem statement with the help of examples.<br \/>\nLet\u2019s say we are given the sorted linked list : head -&gt; 1 -&gt; 1 -&gt; 2 -&gt; 4 -&gt; 6 -&gt; 7 -&gt; NULL and K = 8.<\/p>\n<ul>\n<li>Then here, we will make a pair of the first 1 with 7.<\/li>\n<li>After that we cannot make a pair of the 2<sup>nd<\/sup> 1 with 7 because this 7 has been already used in one of the pairs.<\/li>\n<li>Now we have a pair of 2 and 6.<\/li>\n<li>So our answer pairs would be (1,7) and (2,6).<\/li>\n<\/ul>\n<p>Let\u2019s move to the next section to see this process in more depth.<\/p>\n<h3>Approach 1<\/h3>\n<p>The naive way to do this problem is to traverse over each element one by one and search for the second element in the remaining linked list in a forwarding direction whose sum with the first value is equal to the given value K.<\/p>\n<h4>Algorithm<\/h4>\n<ul>\n<li>Take two-pointer ptr1 and ptr2 pointing to head initially.<\/li>\n<li>Take ptr1\u2192data as the first value and search for the K &#8211; (ptr1\u2192data) as the second value in the remaining linked lists in the forwarding direction.<\/li>\n<li>We find the K-(ptr1-&gt;data) using a pointer ptr2. So if there exists a ptr2 such that ptr1-&gt;data + ptr2-&gt;data == k then we print ptr1-&gt;data and ptr2-&gt;data and delete node pointed by ptr2 as we mentioned in the problem statement that one node should be considered in only one pair.<\/li>\n<li>So if we don\u2019t delete ptr2 then it may be counted again for some other duplicate ptr1-&gt;data. <\/li>\n<li>Like in the example linked list  head -&gt; 1 -&gt; 1 -&gt; 2 -&gt; 4 -&gt; 6 -&gt; 7 -&gt; NULL and k = 8 here 7 can be considered in for both 1\u2019s if we don\u2019t delete it after considering it once.<\/li>\n<li>Now, increment ptr1 = ptr1\u2192next and assign ptr1 to ptr2 because in search of the second element the ptr2 reaches the end of the linked list.<\/li>\n<li>Do the same work for every element till ptr1\u2192data &lt;= K\/2, because if we are traversing for nodes that have ptr1\u2192data greater than K\/2 then we have to search for value K &#8211; (ptr1\u2192data) that is smaller than ptr1\u2192data, and it is impossible to find that value in remaining linked list which is sorted.  <\/li>\n<\/ul>\n<p><strong>Time Complexity:<\/strong>  O(N<sup>2<\/sup>), because for every element, we are searching for its pair.<br \/>\n<strong>Space Complexity:<\/strong> O(1), No extra space is used.<\/p>\n<h3>Dry Run for approach 1<\/h3>\n<p><strong>For better understanding follow dry run along with code<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA1.1.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA1.2.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA1.3.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA1.4.png\" alt=\"\" \/><\/p>\n<h3>Approach 2<\/h3>\n<p>We can apply some optimization to our previous approach by using hashtable\/map.<\/p>\n<h4>Algorithm<\/h4>\n<ul>\n<li>We will insert every value of the sorted linked list as a key in the hashtable\/map. And keep the count of occurrences of every distinct value.<\/li>\n<li>Take a pointer ptr1 initially pointing to the head.<\/li>\n<li>We will start traversing over every element of the linked list till ptr1\u2192datadata) is present in the hashtable and its frequency is more than one then print ptr1-&gt;data and (K &#8211; ptr1-&gt;data).<\/li>\n<li>And decrement the occurrence of (K &#8211; ptr1-&gt;data) to ensure that the same element is not counted in more than one pair.<\/li>\n<li>And if ptr-&gt;data == (k-ptr-&gt;data) then the frequency of ptr-&gt;data should be more than 1 to be considered as a valid pair. And we will print ptr-&gt;data and (k-ptr-&gt;data) (ptr-&gt;data)\/2 times.<\/li>\n<\/ul>\n<p><strong>Time Complexity:<\/strong>  O(N), because for every element, we are searching for its pair and searching in the hashtable is O(1).<br \/>\n<strong>Space Complexity:<\/strong> O(N) because we are keeping a hashtable.<\/p>\n<h3>Dry Run for approach 2<\/h3>\n<p><strong>For better understanding follow dry run along with code<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA2.1.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA2.2.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA2.3.png\" alt=\"\" \/><\/p>\n<p>Finally, we have optimized our solution and now our time complexity is O(N) but we are using extra space which is against the problem statement because we have to find all the  pairs whose sum is equal to K without using extra space.<\/p>\n<h3>Approach 3<\/h3>\n<p>The efficient solution to this problem is to use an XOR linked list.<br \/>\nIn a singly linked list, we can traverse the list only in the forward direction. But if we use XOR concept to convert a singly linked list to doubly linked list then we can travel in the singly-linked in both directions.<br \/>\nNow we will use the concept of two pointers because we can move in both directions by exploiting the property of XOR.<br \/>\nSo the main idea here is that since the linked list is sorted, we will keep a pointer ptr1 at the beginning of the list and another pointer ptr2 at the end of the list.<br \/>\nAnd now if <strong>ptr1-&gt;data + ptr2-&gt;data data+ptr2-&gt;data hence we will move ptr1=ptr1-&gt;next.<br \/>\nIf <\/strong>ptr1-&gt;data + ptr2-&gt;data &gt; k<strong> then it means that we have to decrease the sum ptr1-&gt;data + ptr2-&gt;data hence we will move ptr2 one step backward analogous to ptr2&#8211;.<br \/>\nAnd if <\/strong>ptr1-&gt;data + ptr2-&gt;data == K__ then we have found one required pair so print them and move ptr1 to point to the next node and ptr2 to point to one previous node. <\/p>\n<h4>Algorithm<\/h4>\n<ul>\n<li>We know that in the singly linked list we have only the address of the next node not of the previous node, so we have to convert our singly linked list into a doubly linked list.<\/li>\n<li>The doubly linked list we are talking about here is XOR linked list, which is also known as memory efficient doubly linked list. <\/li>\n<li>The next pointer of each node in the XOR linked list contains the XOR of the previous node\u2019s address and the next node\u2019s address.<\/li>\n<li>After converting singly linked list into XOR linked list we will initialize two pointers ptr1 and ptr2 variables the ptr1 will be assigned with the head and the ptr2 will be assigned with the last node\u2019s address.<\/li>\n<li>If ptr1\u2192data + ptr2\u2192data == K then print both ptr1\u2192data and ptr2\u2192data,but if ptr1\u2192data + ptr2\u2192data &gt; K then we move ptr2 in backward direction by find out the address of the previous node using xor\u2019s property  and if ptr1\u2192data + ptr2\u2192data &lt; K then we move ptr1 in forward direction.<\/li>\n<li>The above action will execute till ptr1 == ptr2.   <\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/example-1.png\" alt=\"\" \/><\/p>\n<h3>Dry Run for approach 3<\/h3>\n<p><strong>For better understanding follow dry run along with code<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA3.1.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA3.2.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA3.3.png\" alt=\"\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/prepbytes.com\/blog\/wp-content\/uploads\/2021\/09\/DRA3.4.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_4868 {\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_4868 .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_4868 .wpsm_nav-tabs {\r\n    border-bottom: 0px solid #ddd;\r\n}\r\n#tab_container_4868 .wpsm_nav-tabs > li.active > a, #tab_container_4868 .wpsm_nav-tabs > li.active > a:hover, #tab_container_4868 .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_4868 .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_4868 .wpsm_nav-tabs > li > a:focus {\r\noutline: 0px !important;\r\n}\r\n\r\n#tab_container_4868 .wpsm_nav-tabs > li > a:before {\r\n\tdisplay:none !important;\r\n}\r\n#tab_container_4868 .wpsm_nav-tabs > li > a:after {\r\n\tdisplay:none !important ;\r\n}\r\n#tab_container_4868 .wpsm_nav-tabs > li{\r\npadding:0px !important ;\r\nmargin:0px;\r\n}\r\n\r\n#tab_container_4868 .wpsm_nav-tabs > li > a:hover , #tab_container_4868 .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_4868 .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_4868 .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_4868 .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_4868 .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_4868 .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_4868 .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_4868 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4868 .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_4868 .wpsm_nav-tabs > li {\r\n\t\t\t\t\r\n\t}\r\n\t#tab_container_4868 .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_4868 .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_4868\" >\r\n\t \r\n\t\t\t\t\t<ul class=\"wpsm_nav wpsm_nav-tabs\" role=\"tablist\" id=\"myTab_4868\">\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_4868_1\" aria-controls=\"tabs_desc_4868_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_4868_2\" aria-controls=\"tabs_desc_4868_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\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_4868\">\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_4868_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<stdio.h>\r\n#include<stdlib.h>\r\n#include<stdbool.h>\r\n#include <stdint.h>\r\n\r\nstruct Node\r\n{\r\n    int data;\r\n \r\n    \/* also contains XOR of next and\r\n    previous node after conversion*\/\r\n    struct Node* next;\r\n};\r\n \r\n\/* Given a reference (pointer to pointer) to the head\r\n    of a list and an int, push a new node on the front\r\n    of the list. *\/\r\nvoid insert(struct Node** head_ref, int new_data)\r\n{\r\n    \/* allocate node *\/\r\n    struct Node* new_node =\r\n        (struct Node*) malloc(sizeof(struct Node));\r\n \r\n    \/* put in the data *\/\r\n    new_node->data = new_data;\r\n \r\n    \/* link the old list off the new node *\/\r\n    new_node->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\n\/* returns XORed value of the node addresses *\/\r\nstruct Node* XOR (struct Node *a, struct Node *b)\r\n{\r\n    return (struct Node*) ((uintptr_t)a ^ (uintptr_t)b);\r\n}\r\n \r\n\/\/ Utility function to convert singly linked list\r\n\/\/ into XOR doubly linked list\r\nvoid convert(struct Node *head)\r\n{\r\n    \/\/ first we store address of next node in it\r\n    \/\/ then take XOR of next node and previous node\r\n    \/\/ and store it in next pointer\r\n    struct Node *next_node;\r\n \r\n    \/\/ prev node stores the address of previously\r\n    \/\/ visited node\r\n    struct Node *prev = NULL;\r\n \r\n    \/\/ traverse list and store xor of address of\r\n    \/\/ next_node and prev node in next pointer of node\r\n    while (head != NULL)\r\n    {\r\n        \/\/ address of next node\r\n        next_node = head->next;\r\n \r\n        \/\/ xor of next_node and prev node\r\n        head->next = XOR(next_node, prev);\r\n \r\n        \/\/ update previous node\r\n        prev = head;\r\n \r\n        \/\/ move head forward\r\n        head = next_node;\r\n    }\r\n}\r\n \r\n\/\/ function to Find pair whose sum is equal to\r\n\/\/ given value x\r\nvoid pairSum(struct Node *head, int x)\r\n{\r\n    \/\/ initialize first\r\n    struct Node *first = head;\r\n \r\n    \/\/ next_node and prev node to calculate xor again\r\n    \/\/ and find next and prev node while moving forward\r\n    \/\/ and backward direction from both the corners\r\n    struct Node *next_node = NULL, *prev = NULL;\r\n \r\n    \/\/ traverse list to initialize second pointer\r\n    \/\/ here we need to move in forward direction so to\r\n    \/\/ calculate next address we have to take xor\r\n    \/\/ with prev pointer because (a^b)^b = a\r\n    struct Node *second = head;\r\n    while (second->next != prev)\r\n    {\r\n        struct Node *temp = second;\r\n        second = XOR(second->next, prev);\r\n        prev = temp;\r\n    }\r\n \r\n    \/\/ now traverse from both the corners\r\n    next_node = NULL;\r\n    prev = NULL;\r\n \r\n    \/\/ here if we want to move forward then we must\r\n    \/\/ know the prev address to calculate next node\r\n    \/\/ and if we want to move backward then we must\r\n    \/\/ know the next_node address to calculate prev node\r\n    bool flag = false;\r\n    while (first != NULL && second != NULL &&\r\n            first != second && first != next_node)\r\n    {\r\n        if ((first->data + second->data)==x)\r\n        {\r\n            printf(\"(%d\",first->data);\r\n            printf(\",%d\",second->data);\r\n            printf(\")\");\r\n \r\n            flag = true;\r\n \r\n            \/\/ move first in forward\r\n            struct Node *temp = first;\r\n            first = XOR(first->next,prev);\r\n            prev = temp;\r\n \r\n            \/\/ move second in backward\r\n            temp = second;\r\n            second = XOR(second->next, next_node);\r\n            next_node = temp;\r\n        }\r\n        else\r\n        {\r\n            if ((first->data + second->data) < x)\r\n            {\r\n                \/\/ move first in forward\r\n                struct Node *temp = first;\r\n                first = XOR(first->next,prev);\r\n                prev = temp;\r\n            }\r\n            else\r\n            {\r\n                \/\/ move second in backward\r\n                struct Node *temp = second;\r\n                second = XOR(second->next, next_node);\r\n                next_node = temp;\r\n            }\r\n        }\r\n    }\r\n    if (flag == false)\r\n        printf(\"No pair found&#92;n\");\r\n}\r\n \r\n\/\/ Driver program to run the case\r\nint main()\r\n{\r\n    \/* Start with the empty list *\/\r\n    struct Node* head = NULL;\r\n    int x = 17;\r\n \r\n    \/* Use insert() to construct below list\r\n    3-->6-->7-->8-->9-->10-->11 *\/\r\n    insert(&head, 11);\r\n    insert(&head, 10);\r\n    insert(&head, 9);\r\n    insert(&head, 8);\r\n    insert(&head, 7);\r\n    insert(&head, 6);\r\n    insert(&head, 3);\r\n \r\n    \/\/ convert singly linked list into XOR doubly\r\n    \/\/ linked list\r\n    convert(head);\r\n    pairSum(head,x);\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_4868_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\/\/ find XOR of previous and next node address\r\nstruct Node* XOR (struct Node *a, struct Node *b){ \r\n    return (struct Node*) ((uintptr_t) (a) ^ (uintptr_t) (b)); \r\n} \r\n\r\n\r\n\/\/ convert singly linked list to XOR linked list\r\nvoid convertSinglyToXORlist(struct Node *head){\r\n    struct Node *next_node; \r\n    struct Node *prv = NULL;  \r\n    while (head != NULL){  \r\n        next_node = head-&gt;next;  \/\/next node \r\n        head-&gt;next = XOR(next_node, prv);\/\/ finding XOR of prv and next Node \r\n        prv = head; \r\n        head = next_node; \r\n    } \r\n} \r\n\r\nvoid pairSumToK(struct Node *head, int K){\r\n\r\n    \/\/both first and second pointer initialized with head\r\n    struct Node *first = head; \r\n    struct Node *second = head; \r\n\r\n    struct Node *next_node = NULL, *prv_node = NULL; \r\n\r\n    while (second-&gt;next != prv_node){ \r\n        struct Node *temp = second; \r\n        second = XOR(second-&gt;next, prv_node); \r\n        prv_node = temp; \r\n    } \r\n \r\n    next_node = NULL; \r\n    prv_node = NULL; \r\n\r\n    while (first != NULL &amp;&amp; second != NULL &amp;&amp; first != second &amp;&amp; first != next_node){ \r\n        if ((first-&gt;data + second-&gt;data)==K){\r\n            \/\/ sum of first Node and second Node's data is equal to K\r\n            \/\/ then print its value  \r\n            cout&lt;&lt;first-&gt;data&lt;&lt;&quot; &quot;&lt;&lt;second-&gt;data&lt;&lt;endl; struct=&quot;&quot; node=&quot;&quot; *temp=&quot;first;&quot; first=&quot;XOR(first-&quot;&gt;next,prv_node); \r\n            prv_node = temp; \r\n\r\n            temp = second; \r\n            second = XOR(second-&gt;next, next_node); \r\n            next_node = temp; \r\n        } \r\n        else\r\n        { \r\n            if ((first-&gt;data + second-&gt;data) &lt; K){ \r\n            \/\/ if sum of first and second node's data is smaller than k\r\n            \/\/ move first pointer forward\r\n                struct Node *temp = first; \r\n                first = XOR(first-&gt;next,prv_node); \r\n                prv_node = temp; \r\n            } \r\n            else{\r\n            \/\/ if sum of first and second node's data is greater than k\r\n            \/\/ move second pointer backward\r\n                struct Node *temp = second; \r\n                second = XOR(second-&gt;next, next_node); \r\n                next_node = temp; \r\n            }\r\n        } \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\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_4868 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_4868 a\"),jQuery(\"#tab-content_4868\"));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>(1,7)<br \/>\n(2,6)<\/p>\n<p><strong>Time Complexity:<\/strong> O(N), because we have traversed through every node of the linked list.<br \/>\n[forminator_quiz id=&#8221;4869&#8243;]<\/p>\n<p>So, in this blog, we have learned to  Find pairs for a given sum in a sorted singly linked list without extra space, and in this process, we also learn how to build intuition regarding any problem and how to optimize the solution. If you want to solve more questions on Linked List, which are curated by our expert mentors at PrepBytes, you can follow this link <a href=\"https:\/\/mycode.prepbytes.com\/interview-coding\/practice\/linked-list\">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 a linked list can be a huge plus point in coding interviews. Problem Statement In this problem, we are given a sorted singly linked list and a value k, our [&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-4867","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>Find pair for given sum in a sorted singly linked without extra space | Linked List | Prepbytes<\/title>\n<meta name=\"description\" content=\"Learn to find pairs with a given sum in a sorted linked list. This blog explains how to build intuition regarding any problem and how to optimize the solution.\" \/>\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\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Find pair for given sum in a sorted singly linked without extra space | Linked List | Prepbytes\" \/>\n<meta property=\"og:description\" content=\"Learn to find pairs with a given sum in a sorted linked list. This blog explains how to build intuition regarding any problem and how to optimize the solution.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-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-14T12:07:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-19T00:09:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/\"},\"author\":{\"name\":\"PrepBytes\",\"@id\":\"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e\"},\"headline\":\"Find pair for given sum in a sorted singly linked without extra space\",\"datePublished\":\"2021-09-14T12:07:26+00:00\",\"dateModified\":\"2022-04-19T00:09:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/\"},\"wordCount\":1283,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/43.205.93.38\/#organization\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png\",\"articleSection\":[\"Linked list articles\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/\",\"url\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/\",\"name\":\"Find pair for given sum in a sorted singly linked without extra space | Linked List | Prepbytes\",\"isPartOf\":{\"@id\":\"http:\/\/43.205.93.38\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png\",\"datePublished\":\"2021-09-14T12:07:26+00:00\",\"dateModified\":\"2022-04-19T00:09:22+00:00\",\"description\":\"Learn to find pairs with a given sum in a sorted linked list. This blog explains how to build intuition regarding any problem and how to optimize the solution.\",\"breadcrumb\":{\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#primaryimage\",\"url\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png\",\"contentUrl\":\"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-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\":\"Find pair for given sum in a sorted singly linked without 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":"Find pair for given sum in a sorted singly linked without extra space | Linked List | Prepbytes","description":"Learn to find pairs with a given sum in a sorted linked list. This blog explains how to build intuition regarding any problem and how to optimize the solution.","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\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/","og_locale":"en_US","og_type":"article","og_title":"Find pair for given sum in a sorted singly linked without extra space | Linked List | Prepbytes","og_description":"Learn to find pairs with a given sum in a sorted linked list. This blog explains how to build intuition regarding any problem and how to optimize the solution.","og_url":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/","og_site_name":"PrepBytes Blog","article_publisher":"https:\/\/www.facebook.com\/prepbytes0211\/","article_published_time":"2021-09-14T12:07:26+00:00","article_modified_time":"2022-04-19T00:09:22+00:00","og_image":[{"url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png","type":"","width":"","height":""}],"author":"PrepBytes","twitter_card":"summary_large_image","twitter_misc":{"Written by":"PrepBytes","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#article","isPartOf":{"@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/"},"author":{"name":"PrepBytes","@id":"http:\/\/43.205.93.38\/#\/schema\/person\/39fcf072e04987f16796546f2ca83c2e"},"headline":"Find pair for given sum in a sorted singly linked without extra space","datePublished":"2021-09-14T12:07:26+00:00","dateModified":"2022-04-19T00:09:22+00:00","mainEntityOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/"},"wordCount":1283,"commentCount":0,"publisher":{"@id":"http:\/\/43.205.93.38\/#organization"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png","articleSection":["Linked list articles"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/","url":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/","name":"Find pair for given sum in a sorted singly linked without extra space | Linked List | Prepbytes","isPartOf":{"@id":"http:\/\/43.205.93.38\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#primaryimage"},"image":{"@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#primaryimage"},"thumbnailUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png","datePublished":"2021-09-14T12:07:26+00:00","dateModified":"2022-04-19T00:09:22+00:00","description":"Learn to find pairs with a given sum in a sorted linked list. This blog explains how to build intuition regarding any problem and how to optimize the solution.","breadcrumb":{"@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-extra-space\/#primaryimage","url":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png","contentUrl":"https:\/\/prepbytes-misc-images.s3.ap-south-1.amazonaws.com\/assets\/1645001044417-Article_142.png"},{"@type":"BreadcrumbList","@id":"https:\/\/prepbytes.com\/blog\/find-pair-for-given-sum-in-a-sorted-singly-linked-without-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":"Find pair for given sum in a sorted singly linked without 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\/4867","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=4867"}],"version-history":[{"count":6,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4867\/revisions"}],"predecessor-version":[{"id":7908,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/posts\/4867\/revisions\/7908"}],"wp:attachment":[{"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/media?parent=4867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/categories?post=4867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prepbytes.com\/blog\/wp-json\/wp\/v2\/tags?post=4867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}