Intuitive Java Solution With Explanation
Idea\nFor the given length n, we first divide it in to k equal parts of size m, any remaninging nodes r must be distributed one by one starting from the first l
**Idea**\nFor the given length `n`, we first divide it in to `k` equal parts of size `m`, any remaninging nodes `r` must be distributed one by one starting from the first list.\nThere is a special case If `m==0`, we already distributed one node per list ( with `res[j++] = curr;`) before we come to `r` part, so deduct `k` from reminder `r`.\n\n```\npublic ListNode[] splitListToParts(ListNode root, int k) {\n        int n = 0;\n        ListNode curr = root;\n        while(curr != null){\n            ++n;\n            curr = curr.next;\n        }\n        int m = n/k, r = (n % k), j = 0;\n        if(m == 0) r -= k;\n        ListNode[] res = new ListNode[k];\n        curr = root;\n        while(curr != null){\n            res[j++] = curr;\n            for(int i=1; i < m; i++){\n                curr = curr.next;\n            }\n            if(r > 0){\n                curr = curr.next;\n                --r;\n            }\n            ListNode tmp = curr.next;\n            curr.next = null;\n            curr = tmp;\n        }\n        return res;\n    }\n```
[]