🔥🔥Beats 100% | Easiest Approach 🚀🚀 | Must Watch 😎
\uD83E\uDD14 Intuition:\n- Traverse through list1 to find the nodes at positions a and b and their previous nodes.\n- Identify the end node of list2.\n- Link th
\uD83E\uDD14 **Intuition:**\n- Traverse through `list1` to find the nodes at positions `a` and `b` and their previous nodes.\n- Identify the end node of `list2`.\n- Link the previous node of `a` to the head of `list2`.\n- Link the end node of `list2` to the node following `b`.\n\n\uD83D\uDEE0\uFE0F **Approach:**\n1. Initialize pointers `temp1`, `prev`, and `temp2` to traverse `list1`, where `temp1` points to the node at position `a`, `prev` points to the node before `a`, and `temp2` points to the node at position `b`.\n2. Traverse `list2` to find its end node, `tail`.\n3. Connect `prev` to the head of `list2` and `tail` to the node following `temp2`.\n4. Return the modified `list1`.\n\n\u23F0 **Time Complexity:**\n- Traversing `list1` and `list2` takes O(n + m), where n and m are the lengths of the lists respectively.\n\n\uD83D\uDCBE **Space Complexity:**\n- The space complexity is O(1) since we are using constant extra space.\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\nclass Solution {\npublic:\n    ListNode* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {\n        ios_base::sync_with_stdio(false);\n        cin.tie(0);\n        cout.tie(0);\n        \n        \n        ListNode *temp1 = list1;\n        ListNode *prev = list1;\n        ListNode *temp2 = list1;\n        ListNode *tail = list2;\n\n        int index = 0;\n        while(temp1 != 0 and index < a)\n        {\n            prev = temp1;\n            temp1 = temp1->next;\n            index++;\n        }\n\n        index = 0;\n        while(temp2 != 0 and index < b)\n        {\n            temp2 = temp2->next;\n            index++;\n        }\n\n        while(tail != 0 and tail->next != 0) \n        tail = tail->next;\n\n        cout << prev->val << " " << temp2->val << endl;\n\n        prev->next = list2;\n        tail->next = temp2->next;\n\n        return list1;\n    }\n};\n```\nUPVOTE IF YOU FIND THIS HELPFUL!!\n![ezgif-6-5fac43137d.gif](https://assets.leetcode.com/users/images/c1a68402-2f86-4e44-8954-d5052a182c6e_1710901234.600894.gif)\n\n
['Linked List', 'C', 'Python', 'C++', 'Java', 'JavaScript']