FastPrepFastPrep
Problem Brief

Get Minimum Round Trip Cost (: for E4 && E5 :)

FULLTIMEPHONE SCREEN

Hi~ The other question asked together was LC863 :) Thanks to the OP! Wish OP all the best!

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). For example, departing = [1,2,3,4] and returning = [4,3,2,1], the minimum cost for round trip will be 2 i.e departing[0] + returning[3]. Solve this in O(n) time.

1Example 1

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

Constraints

Limits and guarantees your solution can rely on.

🤓
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.