← Bloomberg Interview Insights

Bloomberg·Software Engineer·Onsite - Coding / Algorithms·Intermediate

IntermediatePrefer not to say
Apr 2026New York

Summary

Bloomberg onsite coding round for a software engineer role. One algorithmic problem the whole time, but it had enough layers to keep things interesting for a while.

Questions Asked (1)

Q1

You have n candidates, each with a cost to fly to New York and a cost to fly to San Francisco. Exactly ceil(n/2) candidates must go to New York and the rest to San Francisco. Find the minimum total travel cost. Also write unit tests covering edge cases like n=1 and odd n.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was brute force and I actually said that out loud which, fine, but I should've pivoted faster.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints and edge cases, then propose a greedy solution: compute the cost difference (NY - SF) for each candidate, sort by this difference, assign the ceil(n/2) candidates with the smallest differences to NY and the rest to SF. Finally, discuss unit tests covering n=1, odd n, and cases where all differences are equal or extreme.

Pro tip: Mention that this greedy approach is optimal because swapping any two candidates across cities would increase total cost, and explicitly state the time complexity O(n log n) due to sorting. Also, proactively discuss how to handle ties in differences and verify with a brute-force check for small n.

1. Clarify requirements and edge cases

Confirm the exact number of candidates going to NY (ceil(n/2)) and SF (floor(n/2)), and discuss edge cases like n=1, n=0, and odd n. Ask if costs are non-negative integers or can be floats.

2. Derive the greedy strategy

For each candidate, compute the difference d_i = cost_NY_i - cost_SF_i. Sorting by d_i ascending and assigning the first ceil(n/2) to NY minimizes total cost because it minimizes the sum of differences for NY-assigned candidates.

3. Prove optimality

Argue that any other assignment would require swapping a NY-assigned candidate with a SF-assigned candidate, which would increase total cost by d_j - d_i >= 0 since d_i <= d_j. Thus the greedy assignment is optimal.

4. Implement and analyze complexity

Write code that sorts candidates by difference and sums costs accordingly. State time complexity O(n log n) and space O(n) (or O(1) extra if sorting in place).

5. Design unit tests

List test cases: n=1 (only NY), n=2 (one each), n=3 (two NY, one SF), n=4 (two each), all differences equal, all differences positive/negative, and large random cases compared against brute force for small n.

Key Points to Mention

  • Greedy algorithm based on cost difference (NY - SF)
  • Sorting by difference and assigning the smallest differences to NY
  • Proof of optimality via exchange argument
  • Time complexity O(n log n) and space complexity O(n)
  • Edge cases: n=1, odd n, ties in differences, negative costs
  • Unit tests: boundary cases, brute-force verification for small n

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.