Reported March 2026
Bloomberggreedy

Two City Scheduling with an Odd Candidate Count

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt on this Bloomberg OA, reported March 2026, is splitting the group in half with floor division and calling it done. This is Two City Scheduling with a twist: when n is odd, New York gets ceil(n / 2) candidates, not n / 2. It's a greedy sort problem, and the odd-count quota is the part that quietly fails hidden tests. Example 3 has a single candidate who must go to New York even though San Francisco is cheaper. If you blank on the exchange argument during the assessment, StealthCoder is the safety net running invisibly on your screen.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to start by sending everyone to San Francisco, then decide who to move to New York. Moving candidate i changes the total by newYorkCost - sanFranciscoCost. Sort by that difference ascending and move the first ceil(n / 2) candidates to New York. The rest stay in San Francisco. Equivalently, sort by costs[i][0] - costs[i][1] and sum the first k NY costs and the remaining SF costs. The pitfall is the quota. Use (n + 1) / 2 in integer math, not n / 2. Check it against Example 2 and Example 3 before you submit. Also accumulate the sum in a 64-bit type, since 100000 candidates times 100000 cost overflows 32 bits. Sorting makes it O(n log n), which is fine for n up to 100000. If the greedy justification slips away mid-assessment, StealthCoder can surface the sorted-difference solution so you can verify the quota and move on.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Two City Scheduling with an Odd Candidate Count cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as two city scheduling. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Two City Scheduling with an Odd Candidate Count FAQ

What's the trick to this Bloomberg problem?+

Sort candidates by newYorkCost minus sanFranciscoCost. The smallest differences are the ones where New York is relatively cheapest. Send the first ceil(n / 2) to New York and the rest to San Francisco. That greedy choice is provably optimal because each swap affects the total by exactly that difference.

Why does the odd candidate count matter so much?+

The original version assumes an even split. Here New York gets ceil(n / 2), so n = 3 sends two to New York and n = 1 sends one. Using n / 2 with integer division gives the wrong quota on odd inputs and fails Examples 2 and 3.

Do I need dynamic programming?+

No. DP works and runs in O(n^2) with a count of New York assignments, but that's too slow for n up to 100000. The greedy sort by cost difference gives O(n log n) and is the intended solution.

Can the total overflow?+

Yes. With up to 100000 candidates and costs up to 100000, the sum can reach 10 billion, which exceeds a 32-bit integer. The function returns long for that reason, so accumulate in a 64-bit variable.

How do I prepare for this in 48 hours?+

Write the sorted-difference solution from scratch once, then run the three examples by hand, especially the n = 1 and n = 3 cases. Make sure you can explain why sorting by difference works. That covers the pattern and the edge case the OA is testing.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it