Problem statement

https://binarysearch.com/problems/Flight-Scheduling/

Solution

Equal to Leetcode 1029. Two City Scheduling.

Complexity

It is O(n log n) for time and O(n) for space.

Code

class Solution:
    def solve(self, costs):
        FirstCity = [i for i,j in costs]
        Diff = [j - i for i,j in costs]
        return sum(FirstCity) + sum(sorted(Diff)[:len(costs)//2])