Problem · Array

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

Learn this problem
MediumMeta logoMetaFULLTIMEPHONE SCREEN
See Meta hiring insights

Problem statement

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.

Function

getMinimumRoundTripCost(departing: int[], returning: int[]) → int

Examples

Example 1

departing = [1, 2, 3, 4]returning = [4, 3, 2, 1]return = 2
😱

Constraints

🤓

More Meta problems

drafts saved locally
public int getMinimumRoundTripCost(int[] departing, int[] returning) {
  // write your code here
}
departing[1, 2, 3, 4]
returning[4, 3, 2, 1]
expected2
checking account