Very Easy Java Solution 💯 || Beats 100% 🚀 || O(n) Time Complexity
Intuition\n Describe your first thoughts on how to solve this problem. \nFirst we have to find what will the the length of LinkedList at each index in the array
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nFirst we have to find what will the the length of LinkedList at each index in the array of size K.\nFor Example: Input: head = [1,2,3,4,5,6,7,8,9,10], k = 3\nThen our array should be arr = [4, 3, 3] which depicts that at index 0 our LinkedList should be of lenght 4, at index 1 our LinkedList should be of lenght 3 and likewise.\nNow using this array we will create our answer array of type ListNode and each index will contain the head of LinkedList of the length arr[i].\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Find the length of LinkedList given.\n2. Create an array of size k whose indexes will contain the size of LinkedList we will have at every index in the answer array we have to return.\n3. For traverse from 0 to k to populate the answer array. ans[i] will contain the head of sperated linked list.\n# Complexity\n- Time complexity:$$O(n+k)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(k)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * public class 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 */\nclass Solution {\n    public ListNode[] splitListToParts(ListNode head, int k) {\n        int size = getSize(head);\n        int[] arr = getArray(size, k);\n\n        ListNode[] ans = new ListNode[k];\n        ListNode newNode = head;\n        for(int i=0;i<k;i++) {\n\n            ans[i] = newNode;\n\n            int nodeCount = arr[i];\n            ListNode prevNode = null;\n            ListNode currNode = newNode;\n            while(nodeCount > 0) {\n                prevNode = currNode;\n                currNode = currNode.next;\n                nodeCount--;\n            }\n\n            newNode = currNode;\n            if(prevNode != null) {\n                prevNode.next = null;\n            }\n        }\n\n        return ans;\n    }\n\n    private int getSize(ListNode head) {\n        ListNode currNode = head;\n        int size = 0;\n        while (currNode != null) {\n            currNode = currNode.next;\n            size++;\n        }\n        return size;\n    }\n\n    private int[] getArray(int size, int k) {\n        int[] arr = new int[k];\n        int parts = size/k;\n        int extraParts = size%k;\n\n        for(int i=0;i<k;i++) {\n            arr[i] = parts;\n            if(extraParts>0) {\n                arr[i] = arr[i] + 1;\n                extraParts--;\n            }\n        }\n        return arr;\n    }\n}\n```
['Java']