Easiest Fast W/Explanation beats 100% in [ Python3/C++/Python/C#/Java/C ] -- Have a look
Intuition\n\n\n\nC++ []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), 
# Intuition\n![Screenshot 2024-03-20 081126.png](https://assets.leetcode.com/users/images/bb7f00ce-56a1-4f97-8d47-1de0a7fb00bb_1710902591.3511713.png)\n![Screenshot 2024-03-20 081135.png](https://assets.leetcode.com/users/images/cfc313bd-85ec-49fb-a011-a81dc49ddc83_1710902596.1435134.png)\n![Screenshot 2024-03-20 081146.png](https://assets.leetcode.com/users/images/4aeb584c-7f72-4879-afa3-88341d20d3c2_1710902601.0554214.png)\n```C++ []\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        ListNode *f = list1, *s = list1;\n        for (int i = 0; i < a - 1; i++)\n            f = f->next;\n\n        for (int i = 0; i < b; i++)\n            s = s->next;\n\n        f->next = list2;\n        while (list2->next != NULL)\n            list2 = list2->next;\n\n        list2->next = s->next;\n        return list1;\n    }\n};\n```\n```python3 []\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution:\n    def mergeInBetween(\n        self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:\n        f, s = list1, list1\n        for i in range(a - 1):\n            f = f.next\n        for i in range(b):\n            s = s.next\n        f.next = list2\n        while list2.next is not None:\n            list2 = list2.next\n        list2.next = s.next\n        return list1\n```\n```C# []\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     public int val;\n *     public ListNode next;\n *     public ListNode(int val=0, ListNode next=null) {\n *         this.val = val;\n *         this.next = next;\n *     }\n * }\n */\npublic class Solution {\n    public ListNode MergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n        ListNode f = list1 , s = list1;\n        for(var i = 0; i < a - 1; ++i)\n            f = f.next;\n        for(int j = 0; j < b; j++)\n            s = s.next;\n        f.next = list2;\n        while(list2.next != null)\n            list2 = list2.next;\n        list2.next = s.next;\n        return list1;\n    }\n}\n```\n```C []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     struct ListNode *next;\n * };\n */\n\nstruct ListNode* mergeInBetween(struct ListNode* list1, int a, int b, struct ListNode* list2) {\n    struct ListNode *itr = list1, *ptr = NULL, *qtr = NULL, *itr2 = list2;\n    int cnt = 0;\n\n    while (itr) {\n        if (cnt == a - 1)\n            ptr = itr;\n        if (cnt == b + 1)\n            qtr = itr;\n        cnt = cnt + 1;\n        itr = itr->next;\n    }\n\n    itr2 = list2;\n    while (itr2->next)\n        itr2 = itr2->next;\n    ptr->next = list2;\n    itr2->next = qtr;\n    return list1;\n}\n```\n```java []\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n * int val;\n * ListNode next;\n * ListNode() {}\n * ListNode(int val) { this.val = val; }\n * ListNode(int val, ListNode next) { this.val = val; this.next = next; }\n * }\n */\nclass Solution {\n    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n        ListNode f = list1;\n        ListNode s = list1;\n        for (int i = 0; i < a - 1; i++)\n            f = f.next;\n\n        for (int j = 0; j < b; j++)\n            s = s.next;\n        f.next = list2;\n        while (list2.next != null)\n            list2 = list2.next;\n        list2.next = s.next;\n        return list1;\n    }\n}\n```\n```C# []\n/**\n * Definition for singly-linked list.\n * public class ListNode {\n *     public int val;\n *     public ListNode next;\n *     public ListNode(int val=0, ListNode next=null) {\n *         this.val = val;\n *         this.next = next;\n *     }\n * }\n */\npublic class Solution {\n    public ListNode MergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n        ListNode pointerA = list1;\n        ListNode pointerB = list1;\n        \n        for (var i = 0; i < b; i++) {\n            if (i == a - 1) {\n                pointerA = pointerB;\n            }\n            pointerB = pointerB.next;\n        }\n        ListNode pointerC = list2;\n\n        while (pointerC.next != null) {\n            pointerC = pointerC.next;\n        }\n\n        pointerA.next = list2;\n        pointerC.next = pointerB.next;\n        pointerB.next = null;\n        return list1;\n    }\n}\n```\n```python []\n# Definition for singly-linked list.\n# class ListNode(object):\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution(object):\n    def mergeInBetween(self, list1, a, b, list2):\n        """\n        :type list1: ListNode\n        :type a: int\n        :type b: int\n        :type list2: ListNode\n        :rtype: ListNode\n        """\n        f, s = list1, list1\n        for i in range(a - 1):\n            f = f.next\n        for i in range(b):\n            s = s.next\n        f.next = list2\n        while list2.next is not None:\n            list2 = list2.next\n        list2.next = s.next\n        return list1\n```\n```C []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     struct ListNode *next;\n * };\n */\n\nstruct ListNode* mergeInBetween(struct ListNode* list1, int a, int b, struct ListNode* list2) {\n    struct ListNode *f = list1, *s = list1;\n    for (int i = 0; i < a - 1; i++)\n        f = f->next;\n\n    for (int i = 0; i < b; i++)\n        s = s->next;\n\n    f->next = list2;\n    while (list2->next != NULL)\n        list2 = list2->next;\n\n    list2->next = s->next;\n    return list1;\n}\n```\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n Very Simple approach take two pointers on list1 move them on their desired position (move f to a-1th node && b to bth node) .. Now make the f->next as list2 (join list1 to list2) and then move the list2 head\'s pointer to it\'s last position .. after that make list->next = s->next(joins list2\'s last node to slow\'s next node in list1) .. Then finally return list1 ... Here we are not deleting the nodes of list1 which are not required here but they are now not accessible for us .. still bth node -> next is pointing towards the list1 next nodes..\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(1)\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        ListNode *f = list1, *s = list1;\n        for (int i = 0; i < a - 1; i++)\n            f = f->next;\n\n        for (int i = 0; i < b; i++)\n            s = s->next;\n\n        f->next = list2;\n        while (list2->next != NULL)\n            list2 = list2->next;\n\n        list2->next = s->next;\n        return list1;\n    }\n};\n```\n# PLease upvote if it\'s useful for you..\n![th.jpeg](https://assets.leetcode.com/users/images/6c44f3a9-3cb6-49ea-9ade-9b3b37d6722a_1710903052.2520707.jpeg)\n
['Linked List', 'C', 'Python', 'C++', 'Java', 'Python3', 'C#']