FastPrepFastPrep
Problem Brief

Get Minimum Round Trip Cost

OA

There are 2 arrays which denote departing and returning flights with the respective indexes being time and the values of the array being the cost it takes for the flight. Return the minimum cost for a round trip provided the return flight can only be taken at a time post departing flight time (i.e if departing at time i, one can catch a returning flight only from time (i+1) onwards).

Function Description

Complete the function getMinimumRoundTripCost in the editor.

getMinimumRoundTripCost has the following parameters:

  1. 1. int[] departing: an array of integers representing the cost of departing flights
  2. 2. int[] returning: an array of integers representing the cost of returning flights

Returns

int: the minimum cost for a round trip

1Example 1

Input
departing = [1, 2, 3, 4], returning = [4, 3, 2, 1]
Output
2
Explanation

The minimum cost for a round trip can be obtained by taking the departing flight at time 0 with cost departing[0] = 1 and the returning flight at time 3 with cost returning[3] = 1. The total minimum cost is 1 + 1 = 2.

public int getMinimumRoundTripCost(int[] departing, int[] returning) {
    // write your code here
}
Input

departing

[1, 2, 3, 4]

returning

[4, 3, 2, 1]

Output

2

Sign in to submit your solution.