Simple Java Solution
Intuition\nFirst, \nRead and try to understand the problem statement clearly ,\nDon\'t Simply dive into the solution .\nunderstanding the problem clearly solves
# Intuition\nFirst, \nRead and try to understand the problem statement clearly ,\nDon\'t Simply dive into the solution .\nunderstanding the problem clearly solves half of the problem .(not only DSA)\n\nFor Simple understanding of this type problems(especially LinkedList)\nconsider the linked list as a train and the nodes as the compartments of the train . \n\nDecoding the problem in this way forms a better idea of the problem and enhances to think the solution quickly\n\n(Just a Suggestion.....)\n\n# Approach\nfirst we find the size of the linked list\nNow We Have Three Cases \n1. when the size is less than k:\n   then we are left with only one option of adding all the nodes and s\n   and adding null for the remaining nodes\n2. when size equals k :\n   we just simply add all the nodes to the result array\n   Since , we have a linked list of size k and we have to divide into \n   k parts , we just divide one part each.\n3. when size is greater than k :\n   this is the most important part of our solution , \n   let us consider the linked list as a train and the nodes are compartments of the train we have to divide the train into k parts and size > k , \n   How we Tackle this condition : \n   first divide the size into k equal parts and then we are left with \n   some number of boxes/ nodes . we go on from the start by adding \n   the reminder to the divided parts one at a time as the question \n   the differece is max 1.\n\nExample for the third case :\nlet us consider the case Input: head = [1,2,3,4,5,6,7,8,9,10], k = 3\nfirst we divide the array into k equal parts .\ni.e , 10/3 =3 ; (3-3-3)\nnow we are left with another one to arrange ( 10%3=1),\nwe start adding one at a time (since the difference to maintain is 1)\nwe come from start by adding one at a time and decreasing the reminder.\n\nThats the solution \nHope you understand \nThankyou for reading.....\n\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n+k)\n\n# Code\n```java []\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 =0;\n        ListNode temp = head;\n        while(temp!=null){\n            size++;\n            temp = temp.next;\n        }\n        ListNode [] res = new ListNode[k];\n        ListNode temp2 = head;\n        if(k>size){\n            for(int i=0;i<k;i++){\n                if(temp2==null){\n                    res[i]=null;\n                    continue;\n                }\n                res[i]=new ListNode(temp2.val);\n                temp2=temp2.next;\n            }\n\n        }\n        else if(k==size){\n            for(int i=0;i<k;i++){\n                res[i]=new ListNode(temp2.val);\n                temp2=temp2.next;\n            }\n\n        }else{\n            int rem = size%k;\n            int si = size/k;\n            int arr[] = new int[k];\n            Arrays.fill(arr,si);\n            int i=0;\n            while(rem!=0){\n                arr[i]=arr[i]+1;\n                rem--;\n                i++;\n            }\n            ListNode temp3 = head;\n            for(int j =0;j<res.length;j++){\n                ListNode temp4 = temp3;\n                int x =1;\n                while(x!=arr[j]){\n                    temp3=temp3.next;\n                    x++;\n                }\n                ListNode temp5 = temp3;\n                temp3=temp3.next;\n                temp5.next=null;\n                res[j]=temp4;\n            }\n\n        }\n        return res;\n        \n    }\n}\n```
['Linked List', 'Java']