C solution || Beats 100% - O(n) Time Complexity || Efficient and Clean
Intuition\nTo split the linked list into k parts as evenly as possible, calculate the base size q = len / k. Each part should have at least q nodes. If the list
# Intuition\nTo split the linked list into k parts as evenly as possible, calculate the base size ***q = len / k***. Each part should have ***at least q nodes***. If the list can\u2019t be divided evenly, distribute the remainder ***r = len % k*** by giving the ***first r*** parts an ***extra node***, ensuring no two parts differ in size by more than 1.\n\n# Approach\n\t1. Calculate the Length: First, traverse the linked list to count the total number of nodes, len.\n\n\t2.\tDetermine Part Sizes:\n\t\u2022\tThe quotient q = len / k gives the base size of each part.\n\t\u2022\tThe remainder r = len mod k tells us that the first r parts should have q + 1 nodes, and the remaining k - r parts should have q nodes.\n\n\t3.\tSplit the List: Iterate through the list and split it into k parts, taking care to handle the list termination (NULL) correctly for parts that have no nodes.\n\t\u2022\tFor each part, assign q + 1 nodes if it\u2019s one of the first r parts, or q nodes otherwise.\n\t\u2022\tAfter forming each part, disconnect it from the rest of the list by setting head->next = NULL.\n\n\n# Complexity\n- Time complexity: **O(n)**\n\n\n- Space complexity: **O(k)**\n\n\n# Code\n```c []\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     struct ListNode *next;\n * };\n */\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nstruct ListNode** splitListToParts(struct ListNode* head, int k, int* returnSize) {\n    *returnSize = k;\n    struct ListNode** ret = (struct ListNode**)malloc(k*sizeof(struct ListNode*));\n    int len = 0; struct ListNode* temp = head;\n    while(temp){\n        len++;\n        temp = temp->next;\n    }\n    int q = len/k, r = len%k;\n    for(int i=0;i<k;i++){\n        ret[i] = head;\n        int extra = (i < r) ? 1:0;\n        for(int j=1;j<q+extra && head;j++)\n            head = head->next;\n        if(head){\n            struct ListNode* next = head->next;\n            head->next = NULL;\n            head = next;\n        }\n    }\n    return ret;\n}\n```
['C']