🔥✅✅ Beat 97.13% | ✅ Full Explanation ✅✅🔥
Show your appreciation by clicking the upvote button\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n\n\n\n\n\n\n\n\n
# Show your appreciation by clicking the upvote button\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n# UPVOTE\n\n![Screen Shot 2024-03-14 at 11.30.19.png](https://assets.leetcode.com/users/images/99fe0b15-b318-4601-af0f-574bc98640ee_1710652249.4421208.png)\n\n[![Screen Shot 2024-03-20 at 05.07.22.png](https://assets.leetcode.com/users/images/69f248bc-e794-4b06-9423-4ddeafa2ecc5_1710893260.1355925.png)](https://leetcode.com/problems/merge-in-between-linked-lists/submissions/1208633836?envType=daily-question&envId=Invalid%20Date)\n\n\n![AtomicHubUi 2.png](https://assets.leetcode.com/users/images/b4030676-5521-4112-829c-6f5e43bd4a80_1710633960.279035.png)\n\n![Screen Shot 2024-03-14 at 11.30.19 2 2.png](https://assets.leetcode.com/users/images/83ce8492-3ac3-46e8-a736-236bfbd3e309_1710894887.85558.png)\n\n![Screen Shot 2024-03-14 at 11.30.19 2.png](https://assets.leetcode.com/users/images/f098cc93-059b-4072-a4ee-34fde9ac54c5_1710895026.8341432.png)\n\n\n<details>\n<summary><b>Click here to see the text explanation</b></summary>\n<br>\n<br>\n\n1. **Initialization**:\n    - `ptr` is initialized to `list1`. This will serve as a pointer to navigate to the node just before the `a`th node in `list1`.\n    - `qtr` is initialized to the node after `ptr`. This will serve as a pointer to navigate to the node after the `b`th node in `list1`.\n\n2. **Navigating to the Appropriate Positions**:\n    - A loop is used to move `ptr` to the node just before the `a`th node in `list1`. It iterates `a - 1` times.\n    - Another loop is used to move `qtr` to the node after the `b`th node in `list1`. It iterates `b - a + 1` times.\n\n3. **Merging `list2` into `list1`**:\n    - The `next` pointer of the node pointed by `ptr` is updated to point to the head of `list2`, effectively inserting `list2` into `list1` at position `a`.\n    - Then, it traverses through `list2` until it reaches the last node.\n    - Finally, it sets the `next` pointer of the last node of `list2` to point to the node pointed by `qtr`, effectively linking `list2` to `list1` after the removed portion.\n\n4. **Return**: \n    - It returns `list1`, which now represents the merged linked list.\n</details>\n\n<br>\n<br>\n\n```python []\nclass Solution(object):\n    def mergeInBetween(self, list1, a, b, list2):\n        ptr = list1\n        for _ in range(a - 1):\n            ptr = ptr.next\n        \n        qtr = ptr.next\n        for _ in range(b - a + 1):\n            qtr = qtr.next\n        \n        ptr.next = list2\n        while list2.next:\n            list2 = list2.next\n        list2.next = qtr\n        \n        return list1\n```\n```python3 []\nclass Solution:\n    def mergeInBetween(self, list1: ListNode, a: int, b: int, list2: ListNode) -> ListNode:\n        ptr = list1\n        for _ in range(a - 1):\n            ptr = ptr.next\n        \n        qtr = ptr.next\n        for _ in range(b - a + 1):\n            qtr = qtr.next\n        \n        ptr.next = list2\n        while list2.next:\n            list2 = list2.next\n        list2.next = qtr\n        \n        return list1\n```\n```C++ []\nclass Solution {\npublic:\n    ListNode* mergeInBetween(ListNode* list1, int a, int b, ListNode* list2) {\n        ListNode* ptr = list1;\n        for (int i = 0; i < a - 1; ++i)\n            ptr = ptr->next;\n        \n        ListNode* qtr = ptr->next;\n        for (int i = 0; i < b - a + 1; ++i)\n            qtr = qtr->next;\n        \n        ptr->next = list2;\n        while (list2->next)\n            list2 = list2->next;\n        list2->next = qtr;\n        \n        return list1;\n    }\n};\n```\n```javascript []\nvar mergeInBetween = function(list1, a, b, list2) {\n    let ptr = list1;\n    for (let i = 0; i < a - 1; ++i)\n        ptr = ptr.next;\n    \n    let qtr = ptr.next;\n    for (let i = 0; i < b - a + 1; ++i)\n        qtr = qtr.next;\n    \n    ptr.next = list2;\n    while (list2.next)\n        list2 = list2.next;\n    list2.next = qtr;\n    \n    return list1;\n};\n```\n\n![Screen Shot 2024-03-14 at 11.30.19.png](https://assets.leetcode.com/users/images/99fe0b15-b318-4601-af0f-574bc98640ee_1710652249.4421208.png)\n<hr>\n\n*These solutions are sorted from easiest to most challenging problems, tailored to your expertise*\n\n<details>\n<summary><b>Click here to see more of my solutions</b></summary>\n\n## **My solutions**\n\n\uD83D\uDFE2 - easy  \n\uD83D\uDFE1 - medium \n\uD83D\uDD34 - hard\n\n**These solutions are sorted from easiest to most challenging problems, tailored to your expertise.**\n\n\uD83D\uDFE2 [9. Palindrome Number](https://leetcode.com/problems/palindrome-number/solutions/4795373/why-not-1-line-of-code-python-python3-c-everyone-can-understand/)\n\uD83D\uDFE2 [1. Two Sum](https://leetcode.com/problems/two-sum/solutions/4791305/5-methods-python-c-python3-from-easy-to-difficult/)\n\uD83D\uDFE2 [35. Search Insert Position](https://leetcode.com/problems/search-insert-position/solutions/4898401/beat-100-full-explanation-binary-search-demystified)\n\uD83D\uDFE2 [543. Diameter of Binary Tree](https://leetcode.com/discuss/topic/4787634/surpassing-9793-memory-magician-excelling-at-9723/)\n\uD83D\uDFE2 [2864. Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number/solutions/4802402/visual-max-odd-binary-solver-python-python3-javascript-c)\n\uD83D\uDFE2 [2864. Maximum Odd Binary Number](https://leetcode.com/problems/maximum-odd-binary-number/solutions/4802402/visual-max-odd-binary-solver-python-python3-javascript-c)\n\uD83D\uDFE2 [977. Squares of a Sorted Array](https://leetcode.com/problems/squares-of-a-sorted-array/solutions/4807704/square-sorter-python-python3-javascript-c/)\n\uD83D\uDFE2 [876. Middle of the Linked List](https://leetcode.com/problems/middle-of-the-linked-list/solutions/4834682/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE2 [3028. Ant on the Boundary](https://leetcode.com/problems/ant-on-the-boundary/solutions/4837433/full-explanation-with-pictures)\n\uD83D\uDFE2 [3005. Count Elements With Maximum Frequency](https://leetcode.com/problems/count-elements-with-maximum-frequency/solutions/4839796/beat-8369-full-explanation-with-pictures)\n\uD83D\uDFE2 [2540. Minimum Common Value](https://leetcode.com/problems/minimum-common-value/solutions/4845076/beat-9759-full-explanation-with-pictures)\n\uD83D\uDFE2 [101. Symmetric Tree](https://leetcode.com/problems/symmetric-tree/solutions/4848126/beat-100-full-explanation-with-pictures)\n\uD83D\uDFE2 [349. Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/solutions/4850588/beat-100-full-explanation-with-pictures)\n\uD83D\uDFE2 [88. Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/solutions/4856902/beat-100-full-explanation-with-pictures/)\n\uD83D\uDFE2 [136. Single Number](https://leetcode.com/problems/single-number/solutions/4862807/master-the-xor-trick-beat-9720-with-full-explanation)\n\uD83D\uDFE2 [283. Move Zeroes](https://leetcode.com/problems/move-zeroes/solutions/4864068/mastering-efficiency-beat-9871)\n\uD83D\uDFE2 [108. Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/solutions/4864578/mastering-efficiency-beat-8974)\n\uD83D\uDFE2 [2485. Find the Pivot Integer](https://leetcode.com/problems/find-the-pivot-integer/solutions/4866463/beat-100-full-explanation-with-pictures)\n\uD83D\uDFE2 [104. Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/solutions/4876170/beat-100-full-explanation-with-pictures)\n\uD83D\uDFE1 [1669. Merge In Between Linked Lists](https://leetcode.com/problems/merge-in-between-linked-lists/solutions/4898944/beat-97-13-full-explanation)\n\uD83D\uDFE1 [513. Find Bottom Left Tree Value](https://leetcode.com/problems/find-bottom-left-tree-value/solutions/4792022/binary-tree-explorer-mastered-javascript-python-python3-c-10000-efficiency-seeker/)\n\uD83D\uDFE1 [1609. Even Odd Tree](https://leetcode.com/problems/even-odd-tree/solutions/4797529/even-odd-tree-validator-python-python3-javascript-c/)\n\uD83D\uDFE1 [19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/solutions/4813340/beat-10000-full-explanation-with-pictures/)\n\uD83D\uDFE1 [948. Bag of Tokens](https://leetcode.com/problems/bag-of-tokens/solutions/4818912/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE1 [1750. Minimum Length of String After Deleting Similar Ends](https://leetcode.com/problems/minimum-length-of-string-after-deleting-similar-ends/solutions/4824224/beat-10000-full-explanation-with-pictures)\n\uD83D\uDFE1 [17. Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/solutions/4845532/there-is-an-80-chance-of-being-in-the-interview-full-problem-explanation)\n\uD83D\uDFE1 [22. Generate Parentheses](https://leetcode.com/problems/generate-parentheses/solutions/4845742/beat-9334-simple-explanation-with-pictures)\n\uD83D\uDFE1 [39. Combination Sum](https://leetcode.com/problems/combination-sum/solutions/4847482/beat-8292-full-explanation-with-pictures)\n\uD83D\uDFE1 [1171. Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list/solutions/4862064/mastering-efficiency-beat-9231-with-full-explanation-and-visuals)\n\uD83D\uDFE1 [238. Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/solutions/4876797/beat-8080-full-explanation-with-pictures)\n\uD83D\uDFE1 [57. Insert Interval](https://leetcode.com/problems/insert-interval/solutions/4885946/beat-9722-full-explanation-with-pictures)\n\uD83D\uDFE1 [452. Minimum Number of Arrows to Burst Balloons](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/solutions/4890366/beat-9380-full-explanation-with-pictures)\n\uD83D\uDFE1 [131. Palindrome Partitioning](https://leetcode.com/problems/palindrome-partitioning/solutions/4892678/beat-9373-full-explanation-with-pictures)\n\uD83D\uDFE1 [930. Binary Subarrays With Sum](https://leetcode.com/problems/binary-subarrays-with-sum/solutions/4872569/beat-8020-full-explanation-with-pictures)\n\n[More...](https://leetcode.com/DevOgabek/)\n\n</details>\n\n<hr>\n<details>\n<summary><b>Why I do not respond to negative comments</b></summary>\n\n## **Why I do not respond to negative comments**\n![Screen Shot 2024-03-20 at 11.21.18.png](https://assets.leetcode.com/users/images/ec2b5438-9453-43a8-89c6-1b797ab86d13_1710915820.4629908.png)\n\n\n</details>\n\n<hr>\n
['Linked List', 'Python', 'C++', 'Python3', 'JavaScript']