PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW

Quick Overview

Evaluates algorithmic skills in cost-optimization, greedy reasoning and sorting-based assignment while requiring correct handling of constraints and edge cases. Commonly asked in the Coding & Algorithms domain to test a candidate’s ability to design and implement a concrete, implementation-level algorithm and reason about correctness and complexity.

  • easy
  • Bloomberg
  • Coding & Algorithms
  • Software Engineer

Minimize travel cost with two cities

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are scheduling candidates to attend an onsite interview. Each candidate i can fly to New York for cost c1[i] or to San Francisco for cost c2[i]. Constraint: You must send exactly ceil(n/2) candidates to New York, and the remaining candidates to San Francisco. Task: Compute the minimum possible total travel cost. Additionally, write a few unit-style test cases that validate your solution (including edge cases such as n=1 and odd n).

Quick Answer: Evaluates algorithmic skills in cost-optimization, greedy reasoning and sorting-based assignment while requiring correct handling of constraints and edge cases. Commonly asked in the Coding & Algorithms domain to test a candidate’s ability to design and implement a concrete, implementation-level algorithm and reason about correctness and complexity.

You are scheduling candidates for an onsite interview. For each candidate i, flying them to New York costs c1[i], and flying them to San Francisco costs c2[i]. You must send exactly ceil(n / 2) candidates to New York, where n is the total number of candidates, and send the remaining candidates to San Francisco. Return the minimum possible total travel cost.

Constraints

  • 1 <= n == len(c1) == len(c2) <= 200000
  • 0 <= c1[i], c2[i] <= 10^9

Examples

Input: ([30], [5])

Expected Output: 30

Explanation: There is only one candidate, and ceil(1/2) = 1, so that candidate must go to New York even though San Francisco is cheaper.

Input: ([10, 30, 400, 30], [20, 200, 50, 20])

Expected Output: 110

Explanation: Send candidates 0 and 1 to New York, and candidates 2 and 3 to San Francisco. Total = 10 + 30 + 50 + 20 = 110.

Input: ([50, 20, 70], [30, 100, 40])

Expected Output: 110

Explanation: n = 3, so ceil(3/2) = 2 candidates must go to New York. The cheapest valid assignment is candidates 0 and 1 to New York, candidate 2 to San Francisco: 50 + 20 + 40 = 110.

Input: ([5, 5, 5, 5, 5], [5, 5, 5, 5, 5])

Expected Output: 25

Explanation: All costs are identical, so any valid assignment gives the same total cost of 25.

Input: ([100, 100], [1, 1])

Expected Output: 101

Explanation: Exactly one of the two candidates must go to New York. The total is 100 + 1 = 101.

Hints

  1. Try first assuming that everyone goes to San Francisco. Then ask: what is the extra cost or savings if a candidate is switched to New York?
  2. For candidate i, that switch changes the total by c1[i] - c2[i]. Which candidates should be chosen for New York?
Last updated: May 13, 2026

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Solve meeting and tree problems - Bloomberg (easy)
  • Check connectivity between two subway stations - Bloomberg (easy)
  • Design a data structure for dynamic top‑K frequency - Bloomberg (hard)
  • Find tree root and bucket numbers - Bloomberg (hard)
  • Solve common string/tree/grid interview tasks - Bloomberg (medium)