Get Minimum Round Trip Cost
Learn this problemProblem statement
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
getMinimumRoundTripCost(departing: int[], returning: int[]) → int
Complete the function getMinimumRoundTripCost in the editor.
getMinimumRoundTripCost has the following parameters:
- 1.
int[] departing: an array of integers representing the cost of departing flights - 2.
int[] returning: an array of integers representing the cost of returning flights
Returns
int: the minimum cost for a round trip
Examples
Example 1
departing = [1, 2, 3, 4]returning = [4, 3, 2, 1]return = 2The 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.
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026