Split Index Shards Across Two Servers With Exactly Equal Load
Last updated: November 29, 2026
Quick Overview
A search index is split into shards with known sizes, and each shard must go entirely to one of two servers. Decide whether the shards can be split so both servers hold exactly the same total size.
0
0
0 solved
A search index is split into shards with known sizes, and each shard must go entirely to one of two servers. Decide whether the shards can be split so both servers hold exactly the same total size.
Partition into equal sums is a common Google onsite question because it checks 0/1 knapsack fluency and the reverse-iteration trick for a 1D table. Interviewers often follow up on what to do when sizes are huge.
What the Interviewer Expects
- Reject odd totals immediately
- Reduce to subset sum with target total / 2
- Use a 1D boolean table iterated downward
- Explain why downward iteration prevents reuse
- Mention a bitset speedup
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Minimize the difference between the two servers instead.
- Split across k servers with equal load.
- Sizes are up to 10^9 but there are only 40 shards. What now?
- Return which shards go to server A.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list size of positive integers. Output True if some subset sums to exactly half of the total. If the total is odd, the answer is False. Total size up to around for the table approach....
High-Level Design
Let can[s] be True if some subset of shards processed so far sums to s. Initially only can[0]. For each shard of size w, update can[s] |= can[s - w] for s from the target down to w. Going downwa...