Split a Linked Upload Batch Into K Nearly Equal Parts

Last updated: November 29, 2026

Quick Overview

A batch of Google Photos uploads is a singly linked list. Split it into k consecutive parts whose sizes differ by at most one, with larger parts first, returning k heads (some may be None).

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


A batch of Google Photos uploads is a singly linked list. Split it into k consecutive parts whose sizes differ by at most one, with larger parts first, returning k heads (some may be None).

A Google Online Assessment style question about dividing work across k upload workers. The interviewer checks the size math with divmod, cutting each part cleanly, and producing None parts when k exceeds the length.

What the Interviewer Expects
  • Count the length first
  • Use divmod to get base size and number of larger parts
  • Cut each part by setting its tail's next to None
  • Return exactly k entries, padding with None
  • O(n + k) time
Key Topics to Cover
linked list
division of work
divmod
list splitting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Distribute nodes round-robin instead of contiguously.
  • Sizes should be proportional to worker capacity weights.
  • Do it in one pass without knowing the length.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: head and k >= 1.
  • Output: list of k heads; part sizes differ by at most 1 and earlier parts are not smaller than later parts.
  • Parts are consecutive and in original order....
High-Level Design

Count the nodes, n. Then base, extra = divmod(n, k): the first extra parts get base + 1 nodes and the rest get base. Walk the list once more; for each part, record the current node as that part's ...


Submit Your Answer
Markdown supported