FastPrepTwo City Scheduling with an Odd Candidate Count

Two City Scheduling with an Odd Candidate Count

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Each row costs[i] = [newYorkCost, sanFranciscoCost] gives the travel cost for candidate i to attend an onsite interview in one of two cities.

Send exactly ceil(n / 2) candidates to New York and every remaining candidate to San Francisco. Return the minimum possible total travel cost.

Function

minimumTravelCost(costs: int[][]) → long

Examples

Example 1

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

Send the first two candidates to New York and the other two to San Francisco for 10 + 30 + 50 + 20 = 110.

Example 2

costs = [[10,100],[20,30],[30,20]]return = 50

Because n = 3, exactly two candidates go to New York. Sending the first two there and the third to San Francisco costs 10 + 20 + 20 = 50.

Example 3

costs = [[7,3]]return = 7

The New York quota is one, so the only candidate must go to New York even though San Francisco is cheaper.

Constraints

  • 1 <= costs.length <= 100000.
  • costs[i].length = 2.
  • 1 <= costs[i][j] <= 100000.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public long minimumTravelCost(int[][] costs) {
    // Write your code here.
}
costs[[10,20],[30,200],[400,50],[30,20]]
expected110
Checking account…