FRIENDS SEQUENTIAL CROSSING✅✅69_BEATS_100%✅✅🔥Easy Solution🔥With Explanation🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nwe first need to know how many nodes there are in the linked list \nthen we will calcul
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe first need to know how many nodes there are in the linked list \nthen we will calculate how many nodes will each of the k sections have \nwe will use 3 pointers to safely cross and cut the linked list in to the segments we want\nlets see how \n# Approach\n<!-- Describe your approach to solving the problem. -->\nfirst we use a basic while loop to count the no of nodes in the linked list \nthen we will calculate the no of nodes per section \nwe will also see if the remainder is >0 we will add one more node to the current section \nfor k times we move the pointer and cut the link and push it to the result \nif rem ==0 we do the same for k-1 times \nfinally if we dont have a node to push we simply push null \nthats it thank you \n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n![wallhaven-lmkvlr.jpg](https://assets.leetcode.com/users/images/2cedba88-4c11-4f13-a78f-2ff0952aa63b_1725803762.0267303.jpeg)\n\n# Code\n```javascript []\n\nvar splitListToParts = function(head, k) {\n    let count=0\n    let counter=head\n    while(counter){\n        count++\n        counter=counter.next\n    }\n    let quo = Math.floor(count/k)\n    let rem = count%k\n    let res=[]\n    let p1=head\n    for(let z=0;z<k;z++){\n        if(!head){\n            res.push(null)\n            continue\n        }\n        if(rem>0){\n            for(let i=0;i<quo;i++){\n                p1=p1.next\n            }\n            rem--\n        }\n        else{\n            for(let i=0;i<quo-1;i++){\n                p1=p1.next\n            }\n        }\n        let p2=p1.next\n        p1.next=null\n        res.push(head)\n        head=p2\n        p1=p2\n    }\n    return res\n};\n```\n```python []\nclass ListNode:\n    def __init__(self, val=0, next=None):\n        self.val = val\n        self.next = next\n\ndef split_list_to_parts(head: ListNode, k: int) -> List[ListNode]:\n    count = 0\n    current = head\n    \n    while current:\n        count += 1\n        current = current.next\n    \n    quotient, remainder = divmod(count, k)\n    result = []\n    prev = None\n    current = head\n    \n    for _ in range(k):\n        part_head = current\n        for _ in range(quotient + (remainder > 0) - 1):\n            if current:\n                current = current.next\n        if current:\n            prev = current\n            current = current.next\n            prev.next = None\n        result.append(part_head)\n        remainder -= 1\n    \n    return result\n\n```\n```java []\nimport java.util.ArrayList;\nimport java.util.List;\n\nclass 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\npublic class Solution {\n    public List<ListNode> splitListToParts(ListNode head, int k) {\n        int count = 0;\n        ListNode current = head;\n\n        while (current != null) {\n            count++;\n            current = current.next;\n        }\n\n        int quotient = count / k;\n        int remainder = count % k;\n        List<ListNode> result = new ArrayList<>();\n        ListNode prev = null;\n\n        current = head;\n        for (int i = 0; i < k; i++) {\n            ListNode partHead = current;\n            for (int j = 0; j < quotient + (remainder > 0 ? 1 : 0) - 1; j++) {\n                if (current != null) {\n                    current = current.next;\n                }\n            }\n            if (current != null) {\n                prev = current;\n                current = current.next;\n                prev.next = null;\n            }\n            result.add(partHead);\n            remainder--;\n        }\n\n        return result;\n    }\n}\n\n```\n```c []\n#include <stdlib.h>\n\ntypedef struct ListNode {\n    int val;\n    struct ListNode *next;\n} ListNode;\n\nListNode** splitListToParts(ListNode* head, int k, int* returnSize) {\n    int count = 0;\n    ListNode* current = head;\n    \n    while (current) {\n        count++;\n        current = current->next;\n    }\n    \n    int quotient = count / k;\n    int remainder = count % k;\n    *returnSize = k;\n    \n    ListNode** result = (ListNode**)malloc(sizeof(ListNode*) * k);\n    current = head;\n    \n    for (int i = 0; i < k; i++) {\n        ListNode* partHead = current;\n        ListNode* prev = NULL;\n        \n        for (int j = 0; j < quotient + (remainder > 0) - 1; j++) {\n            if (current) {\n                prev = current;\n                current = current->next;\n            }\n        }\n        \n        if (prev) {\n            prev->next = NULL;\n        }\n        \n        result[i] = partHead;\n        remainder--;\n        \n        if (current) {\n            current = current->next;\n        }\n    }\n    \n    return result;\n}\n\n```
['Linked List', 'Math', 'C', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']