Minimum Valid Round-Trip Fare
Problem statement
Two arrays give ticket fares by day: departing[i] is the fare to leave on day i, and returning[j] is the fare to return on day j. Choose a departure day i and a return day j with j >= i. Return the minimum possible total fare departing[i] + returning[j].
For this practice version, the arrays may have different lengths. Their index zero refers to the same day, and returning on the departure day is valid.
Function
minimumValidRoundTripFare(departing: int[], returning: int[]) → intExamples
Example 1
departing = [10,3,10,9,3]returning = [4,20,6,7,10]return = 9Leave on day 1 for 3 and return on day 2 for 6. No valid pair costs less than 3 + 6 = 9.
Example 2
departing = [1,100]returning = [1,100]return = 2Both tickets may be on day 0, for a total fare of 1 + 1 = 2.
Example 3
departing = [8,2]returning = [5,20,1]return = 3Leave on day 1 for 2 and return on day 2 for 1. The return array extends beyond the departure array.
Constraints
1 <= departing.length, returning.length <= 100000.0 <= departing[i], returning[j] <= 1000000000.- The arrays may have different lengths.