Search⌘ K
AI Features

Split Linked List in Parts

Understand how to divide a singly linked list into k consecutive parts with sizes as equal as possible, ensuring earlier parts are larger when necessary. This lesson teaches how to manipulate linked lists in place and handle edge cases, preparing you to solve similar coding interview problems effectively.

Statement

You are given head of a singly linked list and an integer, k. Your task is to split the linked list into k consecutive parts.

  • Each part should have a size as equal as possible, with the difference between any two parts being at most 11.

  • If the list cannot be evenly divided, the earlier parts should have more nodes than the later ones.

  • Any parts that cannot be filled with nodes should be represented as NULL.

  • The parts must appear in the same order as in the input-linked list.

Return an array of ...