FastPrepMinimum Cost to Assign Candidates to Two Cities
Problems/Minimum Cost to Assign Candidates to Two Cities

Minimum Cost to Assign Candidates to Two Cities

Infosys logoInfosys● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: This practice version is about a 60% match to the available source. The 2n candidates, two destination cities, per-candidate travel costs, and minimum-total-cost objective come directly from the source. The equal split between the cities was part of a forgotten condition, while numeric bounds, the function signature, and examples were not shown, so FastPrep filled them in consistently without changing the reported assignment objective.

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[][]) → long

Examples

Example 1

costs = [[10,20],[30,200],[400,50],[30,20]]return = 110

Send 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 = 1859

One 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 = 102

Send 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 <= 100000
  • costs.length is even.
  • costs[i].length == 2
  • 0 <= costs[i][j] <= 1000000000
  • The minimum total cost fits in a signed 64-bit integer.

More Infosys problems

  • Swap Two Gender ValuesPHONE SCREEN · Seen Oct 2026
  • Count Equal-Distinct Character PartitionsOA · Seen Oct 2026
  • Maximize the Even-Odd Index Product GapONSITE INTERVIEW · Seen Oct 2026
All Infosys interview questionsSee Infosys hiring insights
Saved
class Solution {
    public long minimumTwoCityCost(int[][] costs) {
        // write your code here
    }
}
Checking account…