Skip to content
Decoder

Two City Scheduling

Medium

Problem

A company is flying 2n people to interviews. costs[i] = [a, b] is the price of flying person i to city A or to city B. Exactly `n` people must go to each city. Return the minimum total cost.

Example 1

Input
costs = [[10, 20], [30, 200], [400, 50], [30, 20]]
Output
110
Why
A, A, B, B

Example 2

Input
costs = [[20, 10], [10, 20]]
Output
20

Constraints

  • 2 * n == costs.length
  • 2 <= costs.length <= 100
  • costs.length is even.
  • 1 <= a, b <= 1000

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.