Cheapest Round Trip
Updated
Problem statement
Two equal-length arrays describe fares by day: departureFares[i] is the cost to depart on day i, and returnFares[j] is the cost to return on day j.
Given a positive integer minStay, choose days satisfying j - i >= minStay and return the minimum value of departureFares[i] + returnFares[j].
Function
minimumRoundTripFare(departureFares: int[], returnFares: int[], minStay: int) → longExamples
Example 1
departureFares = [8,3,6,2]returnFares = [9,5,4,7]minStay = 1return = 7Depart on day 1 for 3 and return on day 2 for 4.
Example 2
departureFares = [10,2,8,4,9]returnFares = [6,7,3,5,1]minStay = 3return = 3Depart on day 1 for 2 and return on day 4 for 1.
Constraints
- The two fare arrays have the same length of at least
2. 1 <= minStay < departureFares.length.- Every fare is a nonnegative signed integer.
More Uber Onsite Interview questions
- Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
- Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Serialize and Deserialize an N-Ary TreeONSITE INTERVIEW · Seen Oct 2026
- Longest Continuous Subarray Within an Absolute-Difference LimitONSITE INTERVIEW · Seen Oct 2026
- K Smallest Squares from a Sorted ArrayONSITE INTERVIEW · Seen Sep 2026
- Grid Robot Route with Charging PrioritiesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Shortest Increasing Path to a TargetONSITE INTERVIEW · Seen Sep 2026
- My Calendar IONSITE INTERVIEW · Seen Sep 2026
- Per-Element Hit CounterONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Maximum Profit with Exactly One Stock TransactionRetool · PHONE SCREEN · ONSITE INTERVIEWRetool interview questions
- Best Time to Buy and Sell Stock IIGroww · ONSITE INTERVIEW
- Maximize Two Endpoint ValuesGoogle · ONSITE INTERVIEWGoogle interview questions
- Best Time to Buy and Sell StockOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Best Time to Buy and Sell StockZoox · ONSITE INTERVIEW
- Evaluate a Blackjack HandGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Best Time to Buy and Sell StockMotive · ONSITE INTERVIEWMotive interview questions
- Best Time to Buy and Sell StockBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Maximum Profit with Repeated Stock TradesPalantir · ONSITE INTERVIEWPalantir interview questions
- Pair Coders by RatingExpedia · ONSITE INTERVIEWExpedia interview questions