Trains the technique from
LeetCode 1029Two City SchedulingThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A maintenance contractor has 2 * n engineers on the roster and two depots that each need staffing for the week: the northern hub and the southern hub. Exactly n engineers go to the northern hub and the other n go to the southern hub.
You are given costs, where costs[i] = [north_i, south_i]. Sending engineer i to the northern hub costs north_i in travel allowance, and sending that same engineer to the southern hub costs south_i instead.
Return the smallest total allowance the contractor can pay while filling both hubs with exactly n engineers each.
Example 1
Sending engineers 0 and 2 north costs 16 and 55, and sending engineers 1 and 3 south costs 44 and 35, for a total of 150. Two engineers reach each hub, as required.
Example 2
One engineer must go to each hub. Sending engineer 0 north for 7 and engineer 1 south for 7 costs 14 in all.
Example 3
Two engineers still have to travel south at 1000 each. Sending engineers 0 and 1 north for 1 and 2 brings the total to 2003.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def two_city_sched_cost(costs: list[list[int]]) -> int:public int twoCitySchedCost(int[][] costs)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.