FunctionRacerProblemsRace

Split the Team Between Two Offices

MediumGreedyPython, JavaScript, TypeScript, Java, C++

Each item of costs is [a, b]: sending that person to office A costs a and sending them to office B costs b. Exactly half of the people must go to each office; costs always has an even number of items.

Return the smallest possible total cost. The smallest total is unique, so no tie rule is needed. Return 0 for an empty list.

Example 1

costs [[10,20],[30,200],[400,50],[30,20]]
returns 110

Persons 1 and 2 go to A (10 + 30) and persons 3 and 4 go to B (50 + 20): 110.

Example 2

costs [[1,2],[2,1]]
returns 2

Each person goes where they are cheaper: 1 + 1 = 2.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems