Two City Scheduling Problem
Two City Scheduling Problem — ExecCode Easy DSA Practice
Solve the Two City Scheduling problem on ExecCode. Free online easy DSA practice in Greedy. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the i^th person to city a is aCosti, and the cost of flying the i^th person to city b is bCosti. Your task is to compute the required answer and return the minimum cost to fly every person to a city such that exactly n people arrive in each city. A company is planning to interview 2n people.
Examples
Input {"costs": [[10, 20], [30, 200], [400, 50], [30, 20]]}; Output 110. Input {"costs": [[259, 770], [448, 54], [926, 667], [184, 139], [840, 118], [577, 469]]}; Output 1859. Input {"costs": [[515, 563], [321, 809], [899, 127], [145, 87], [723, 424], [931, 317], [704, 672], [790, 446], [422, 74], [434, 498]]}; Output 3507
Constraints
2 * n == costs.length 2 <= costs.length <= 100 costs.length is even. 1 <= aCosti, bCosti <= 1000
Practice Two City Scheduling free on ExecCode. Browse DSA problems, topic map, and placement guides.