Choose K Regions From N for a Replica Placement Plan
Last updated: November 29, 2026
Quick Overview
Given n candidate Google Cloud regions labeled 1 to n and an integer k, return every way to choose k regions for a replica set. Order within a choice does not matter.
0
0
0 solved
Given n candidate Google Cloud regions labeled 1 to n and an integer k, return every way to choose k regions for a replica set. Order within a choice does not matter.
A common Google online assessment item framed around replica placement. The interviewer or grader checks that you generate combinations in increasing order and prune branches that cannot reach k items.
What the Interviewer Expects
- Generates combinations in increasing index order to avoid duplicates
- Prunes when not enough regions remain to fill k slots
- States the count is C(n, k)
- Handles k = 0 and k = n
- Writes iterative or recursive code that runs cleanly
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
- How would you add a constraint that no two chosen regions share a continent?
- How would you return the combinations in lexicographic order lazily?
- What is the cost if you only need the count?
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: integers n and k, with 0 <= k <= n and n up to about 20.
- Output: all C(n, k) combinations, each sorted ascending, for example n = 4, k = 2 gives 6 lists.
- Region labels are 1..n....
High-Level Design
Pick regions in strictly increasing order: after choosing region r, the next pick must be greater than r. That ordering guarantees each combination is generated once.
Pruning: at a node with `len(pat...