Two City Scheduling

MediumGreedygreedy

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A company is flying 2n people to interviews. Person i costs costs[i][0] to fly to city A and costs[i][1] to fly to city B. Exactly n people must go to each city. Return the minimum total cost.

Examples

Input: costs = [[10,30],[40,15],[20,50],[30,20]]
Output: 65
Send persons 0 and 2 to A (10 + 20) and persons 1 and 3 to B (15 + 20).
Input: costs = [[5,9],[8,3]]
Output: 8
Person 0 goes to A for 5 and person 1 goes to B for 3.

Constraints

  • 2 <= costs.length <= 100
  • `costs.length` is even
  • 1 <= costs[i][0], costs[i][1] <= 1000

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More greedy problems