Two City Scheduling
Explore how to solve the Two City Scheduling problem by applying greedy algorithms to minimize total costs. Understand how to assign candidates evenly between two locations while considering individual travel expenses. This lesson helps build skills in optimization and cost-effective decision-making for coding interviews.
We'll cover the following...
Statement
A recruiter plans to hire
We are given an array, costs, where
You need to determine the minimum cost to invite all the candidates for the interview such that exactly
Constraints:
-
costs.length costs.lengthis even
Examples
Understand the problem
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Two City Scheduling
What is the minimum cost to invite every person to two different cities such that the same number of people arrive in each city if the costs are as follows?
[10, 15], [10, 20], [10, 25], [10, 30]?
40
55
75
Figure it out
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself
Implement your solution in main.py in the following coding playground.
def two_city_scheduling(costs):# Replace this placeholder return statement with your codereturn -1