DSA interview question
A video platform splits a long upload into k consecutive segments to encode on k machines in parallel. The job finishes when the slowest machine finishes, so the goal is to split the array of chunk sizes into k contiguous, non-empty parts that minimise the largest part's sum. It's the same problem as book allocation under a different name. Binary search on the answer (the largest allowed part sum) between the biggest single chunk and the total, with a greedy count of how many parts that limit forces.
Example: nums = [7, 2, 5, 10, 8], k = 2 → 18 ([7, 2, 5] and [10, 8]).
int splitArray(const vector<int>& nums, int k); // 1 <= k <= nums.size()
Input (nums, k) | Output | Explanation |
|---|---|---|
([7, 2, 5, 10, 8], 2) | 18 | [7, 2, 5] and [10, 8] |
([1, 2, 3, 4, 5], 2) | 9 | [1, 2, 3] and [4, 5] |
([1, 4, 4], 3) | 4 | One element per part |
([10], 1) | 10 | |
([2, 3, 1, 2, 4, 3], 5) | 4 | For example [2], [3], [1, 2], [4], [3] |
(Confirm: the parts are contiguous and non-empty; k ≤ n.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in