FastPrepGet Minimum Round Trip Cost
Problems/Get Minimum Round Trip Cost

Get Minimum Round Trip Cost

Amazon logoAmazon● EasyOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given two arrays of the same length, departing and returning. Each index is a time, and each value is the cost of a flight at that time: departing[i] is the cost of leaving at time i, and returning[j] is the cost of coming back at time j.

A round trip is one departing flight and one returning flight, and the return must be strictly later than the departure: if you leave at time i, you can only come back at a time j with j ≥ i + 1.

Return the minimum total cost departing[i] + returning[j] over all valid round trips.

Complete the function getMinimumRoundTripCost in the editor. It has the following parameters:

  • int[] departing: the cost of the departing flight at each time
  • int[] returning: the cost of the returning flight at each time

The function returns an int: the minimum cost of a round trip.

Function

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

Examples

Example 1

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

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.

Constraints

  • 2 ≤ n ≤ 105, where n is the length of departing
  • returning.length = departing.length
  • 1 ≤ departing[i] ≤ 109
  • 1 ≤ returning[i] ≤ 109

More Amazon interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Eating CandiesTikTok · OATikTok interview questions
  • Running Through Walls with Limited EnergyScale AI · OAScale AI interview questions
  • Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Count Non-Overlapping Pairs of Rectangles That Sum to KWisdomAI · PHONE SCREEN
  • Count Hotspot Playback WindowsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Subarray with a Given SumExpedia · ONSITE INTERVIEWExpedia interview questions
  • Trapping Rain WaterInMobi · ONSITE INTERVIEWInMobi interview questions
  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Minimum Index Distance Between Person and CakeSnowflake · OA · PHONE SCREENSnowflake interview questions
  • Minimum Positive Starting ValueBooking.com · OA

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int getMinimumRoundTripCost(int[] departing, int[] returning) {
        // write your code here
    }

}
Checking account…