Split Linked List In K Parts

easy
1. You are given a singly linked list N nodes.
   2. You are also given a number K.
   3. You have to write a function that split the linked list into K 
      consecutive linked list "parts".
      Note: 
         1. The length of each part should be as equal as possible: 
            no two parts should have a size differing by more than 1. 
            This may lead to some parts being null.
         2. The parts should be in order of occurrence in the input list, 
            i.e. parts occurring earlier should always have a size greater
            than or equal parts occurring later.
   4. display is a utility function which displays the contents of Linked List,
      feel free to use it for debugging purposes.
   5. main takes input from the users and creates the Linked List. You can use
      display to know its contents.
   6. This is a functional problem. 
   7. You should code only the splitListToParts function. It takes as input the
      head of the linked list and K. It should return an array of heads of the 
      the linked list parts that are formed. 
   8. Don't change the code of Node, main and display.

Input Format

First line takes N, the number of elements in the list. Second line takes input N space separated numbers reperesenting elements of the linked list. Third line takes input K. Input is handled for you.

Output Format

Linked List Parts Output is handled for you.

Constraints

1 <= N <= 1000
   1 <= K <= 100

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
10
1 2 3 4 5 6 7 8 9 10
3
Output
1 2 3 4 
5 6 7 
8 9 10
Previous
Sort Linked List Of 0s 1s And 2s
Next
Subtract Two Linked Lists

Related Questions