Code RoomMinimum candidate flight cost
MediumPrep Room Coding #1507

Minimum candidate flight cost

CodingAlgorithms & data structuresMid–Senior~20 min

A company is interviewing 2n candidates. Flying candidate i to city A costs costs[i][0] and to city B costs costs[i][1]. Exactly n people must go to each city. Return the minimum total cost to fly everyone such that the cities are evenly split. The input has an even length up to 200; all costs are non-negative integers.

Implement
two_city_cost(costs: list[list[int]]) → int
Examples
in[[[10,20],[30,200],[400,50],[30,20]]]out110
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 20 min
InputExpectedGot
[[[10,20],[30,200],[400,50],[30,20]]]110not run yetsample