Deal and Weave
First cut the list into k parts that follow one another. The parts are as equal in length as possible, and when the nodes do not divide evenly, the parts at the front are one node longer. With fewer than k nodes, the last parts are empty.
Then weave the parts into one list: take the first node of part 1, of part 2, and so on up to part k, then the second node of every part, and so on. A part that has run out is skipped.
Return the head of the woven list. The list is passed in as head.
Linked lists appear in the tests as the list of their values, like [1,2,3]. Each node is a ListNode with .val and .next; the class is already defined for you.
Example 1
The parts are 1, 2, 3 and 4, 5 and 6, 7. Weaving takes 1, 4, 6, then 2, 5, 7, then 3.
Example 2
Two parts of two: 1, 2 and 3, 4.
Example 3
Every node is a part of its own, and two parts are empty, so the order stays.
Constraints
0 <= number of nodes <= 60-100 <= node.val <= 1001 <= k <= 60
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.