Split Interview Candidates Evenly Between Two Offices at Least Travel Cost
Last updated: November 29, 2026
Quick Overview
Google must fly 2n onsite candidates to either the Mountain View or the New York office, with exactly n going to each. Given each candidate's flight cost to both offices, return the minimum total travel cost.
0
0
0 solved
Google must fly 2n onsite candidates to either the Mountain View or the New York office, with exactly n going to each. Given each candidate's flight cost to both offices, return the minimum total travel cost.
Recruiting logistics give this classic a believable Google setting. The interviewer checks whether you see that the difference between the two costs is what matters, not the raw costs.
What the Interviewer Expects
- Notice that only the cost difference decides who goes where
- Sort by cost_a minus cost_b
- Send the first half to office A and the rest to B
- Prove the sort with an exchange argument
- O(n log n) time
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
- Allow any split as long as each office gets at least m candidates.
- Three offices with fixed quotas. Is a simple sort still enough?
- Some candidates can only go to one office.
- Return the assignment, not only the cost.
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 of [cost_a, cost_b] pairs of even length 2n. Output: minimum total cost with exactly n candidates at each office....
High-Level Design
Start by imagining everyone flies to office B, costing the sum of all cost_b. Moving candidate i to A changes the total by cost_a - cost_b. We must move exactly n people, so move the n with the sm...