Reference: LeetCode
Difficulty: Medium

## Problem

Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list “parts”.
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.
The parts should be in order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal parts occurring later.
Return a List of ListNode’s representing the linked list parts that are formed.

Note:

• The length of root will be in the range [0, 1000].
• Each value of a node in the input will be an integer in the range [0, 999].
• k will be an integer in the range [1, 50].

Example:

## Analysis

Methods:

1. In-Place
• The length of the list is n.
• There are k groups, so the result should initialized with size k.
• The width of each part is width which is equal to n / k.
• We also notice that the width of some parts at the beginning should width + 1. The number of these parts is n % k.

Time: $O(N)$
Space: $O(k)$ the size of the result.

Comment Junhao Wang
Hi, I was a master student at USC studying Computer Science.