Skip to the code
cf.
+25 XP

#574 Split Interviewers Between Two Offices

medium

A hiring tool books travel for an even number of interviewers. Exactly half must fly to office A and half to office B. costs[i] is [costToA, costToB] for interviewer i.

Write cheapestSplit(costs) that returns the smallest total travel cost that sends exactly half of the interviewers to each office.

Example 1

Input: costs = [[10,20],[30,200],[400,50],[30,20]]
Output: 110

Send the first two to A (10 + 30) and the last two to B (50 + 20).

Example 2

Input: costs = [[5,9],[7,8]]
Output: 13

Sending the first to A and the second to B costs 5 + 8 = 13; the other way costs 16.

Constraints

  • costs.length is even, 0 <= costs.length <= 100000
  • 1 <= costToA, costToB <= 1000
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).