Minimum Cost to Assign Candidates to Two Cities
Learn this problemProblem statement
You are given an even-length matrix costs, where costs[i][0] is the cost of sending candidate i to City A and costs[i][1] is the cost of sending that candidate to City B.
Send every candidate to exactly one city, with exactly half of the candidates assigned to each city.
Return the minimum possible total assignment cost.
Function
minimumTwoCityCost(costs: int[][]) → longExamples
Example 1
costs = [[10,20],[30,200],[400,50],[30,20]]return = 110Send candidates 0 and 3 to City A for 10 + 30, and candidates 1 and 2 to City B for 200 + 50 would cost 290. A cheaper valid split sends candidates 0 and 1 to City A and candidates 2 and 3 to City B, for 10 + 30 + 50 + 20 = 110.
Example 2
costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]return = 1859One minimum-cost assignment sends candidates 0, 3, and 5 to City A, and candidates 1, 2, and 4 to City B.
Example 3
costs = [[1,100],[2,200]]return = 102Send the first candidate to City B and the second candidate to City A, for a total cost of 100 + 2 = 102.
Constraints
2 <= costs.length <= 100000costs.lengthis even.costs[i].length == 20 <= costs[i][j] <= 1000000000- The minimum total cost fits in a signed 64-bit integer.
More infosys problems
- Count Valid A-B-C Sequences Under a Modulo-Four RuleOA · Seen Aug 2026
- Maximum Product of a Strictly Increasing Contiguous SubarrayOA · Seen Aug 2026
- Minimum Path Sum With Grid SwitchesONSITE INTERVIEW · Seen May 2026
- Maximum Subarray Sum After SwapsOA · Seen Feb 2026
- Find Number of Good Subsequences 🍅OA · Seen Apr 2024
- Number of Unique Elements After Modifications 🍁OA · Seen Mar 2024
- Obtain Maximum Score Using Minimum SwapsOA · Seen Feb 2024
- Extract CardsOA · Seen Feb 2024