Practice Two City Scheduling
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti. Return the minimum cost to fly every person to a city such that exactly n people arrive in each city.
Source: Two City Scheduling on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
costs = [[10,20],[30,200],[400,50],[30,20]]
Output
110
# Example 2
Input
costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]
Output
1859
# Example 3
Input
costs = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]]
Output
3086
Constraints
2 * n == costs.length
2 <= costs.length <= 100
costs.length is even.
1 <= aCosti, bCosti <= 1000
Related LeetCode Problems
Practice more problems similar to Two City Scheduling.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.