Split Interview Candidates Between Two Hubs at Minimum Travel Cost

Last updated: November 29, 2026

Quick Overview

2n candidates are flying in for onsite loops, and exactly n must go to the Seattle hub and n to the Arlington hub. costs[i] = [seattle_cost, arlington_cost]. Return the minimum total travel cost.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

0

0

0 solved


2n candidates are flying in for onsite loops, and exactly n must go to the Seattle hub and n to the Arlington hub. costs[i] = [seattle_cost, arlington_cost]. Return the minimum total travel cost.

An Amazon phone screen greedy question where the key insight is sorting by the difference in costs. The interviewer wants a short exchange argument and a check that you respect the exactly-n constraint.

What the Interviewer Expects
  • Sorts by seattle_cost minus arlington_cost
  • Sends the first n to Seattle and the rest to Arlington
  • Explains the exchange argument via differences
  • Runs in O(n log n)
  • Notes the DP alternative for unequal splits
Key Topics to Cover
greedy
sorting by difference
exchange argument
assignment
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
  • The hubs have capacities a and b with a + b = 2n.
  • Three hubs with capacities: does greedy still work?
  • Some candidates can only go to one hub.
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: list of 2n pairs of positive costs. Output: minimum sum with exactly n candidates assigned to each hub. I would confirm the list length is even, that every candidate must be assigned (no one ca...

High-Level Design

Start by imagining everyone goes to Arlington; total is the sum of arlington costs. Moving candidate i to Seattle changes the total by seattle_i - arlington_i. We must move exactly n people, so move...


Submit Your Answer
Markdown supported