Modifying the Links | Java | C++
Intuition, approach, and complexity dicussed in video solution in detail.\nhttps://youtu.be/sxUXGlvTWt8\n\n# Code\nC++\n\nclass Solution {\npublic:\n    ListNod
# Intuition, approach, and complexity dicussed in video solution in detail.\nhttps://youtu.be/sxUXGlvTWt8\n\n# Code\nC++\n```\nclass Solution {\npublic:\n    ListNode* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {\n        ListNode *currNode = list1;\n        int index = 0;\n        while(index < a-1){\n            currNode = currNode->next;\n            index++;\n        }\n        ListNode *front = currNode;\n        while(index < b+1){\n           currNode = currNode->next;\n           index++;\n        }\n        ListNode *rear = currNode;\n        ListNode *secondListTail = list2, *secondListHead = list2;\n        while(secondListTail->next != NULL)secondListTail = secondListTail->next;\n        front->next = secondListHead;\n        secondListTail->next = rear;\n        return list1;\n    }\n};\n```\nJava\n```\nclass Solution {\n    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {\n        ListNode currNode = list1;\n        int index = 0;\n        while (index < a - 1) {\n            currNode = currNode.next;\n            index++;\n        }\n        ListNode front = currNode;\n        while (index < b + 1) {\n            currNode = currNode.next;\n            index++;\n        }\n        ListNode rear = currNode;\n        ListNode secondListTail = list2, secondListHead = list2;\n        while (secondListTail.next != null) {\n            secondListTail = secondListTail.next;\n        }\n        front.next = secondListHead;\n        secondListTail.next = rear;\n        return list1;\n    }\n}\n\n```
['Linked List', 'C++', 'Java']