[Python] two passes solution, explained
Just do what is asked carefully: first, find number of nodes N in our list and evaluate d and r: how many times nodes there should be in the first part minus on
Just do what is asked carefully: first, find number of nodes `N` in our list and evaluate `d` and `r`: how many times nodes there should be in the first part minus one. Then we can evaluate number of nodes in every part, using formula `d + (i < r) - 1`, where `i` goes from `0` to `k-1`. In each part, we do `d` (or `d-1` steps), so now we are in the end of this part. If we are not at the `None` node (so, if part has at least one element), then we cut connection between current node and next one and go to the next node.\n\n#### Complexity\nTime complexity is `O(n + k)`, because it can happen that `k` is much bigger than `n`. Space complexity is `O(k)` to write answer.\n\n#### Code\n```python\nclass Solution:\n    def splitListToParts(self, root, k):\n        cur = root\n        N = 0\n        while cur:\n            cur = cur.next\n            N += 1\n        d, r = divmod(N, k)\n\n        ans = []\n        cur = root\n        for i in range(k):\n            head = cur\n            for j in range(d + (i < r) - 1):\n                if cur: cur = cur.next\n            if cur:\n                cur.next, cur = None, cur.next\n            ans.append(head)\n        return ans\n```\n\nIf you have any questoins, feel free to ask. If you like the solution and explanation, please **upvote!**
['Linked List']