FastPrepPlan a Minimum-Cost Round Trip
Problems/Plan a Minimum-Cost Round Trip

Plan a Minimum-Cost Round Trip

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamples

Problem statement

You are given two cost arrays, departing and returning. A departure at index i costs departing[i], and a return at index j costs returning[j].

Choose zero-based indices i and j such that i < j and departing[i] + returning[j] is minimized. Return the two selected indices as [i, j].

If multiple pairs have the same minimum cost, choose the earliest departure index. If there is still a tie, choose the latest return index.

The requested time complexity is O(N).

Function

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

Examples

Example 1

departing = [10,7,8,3,6]returning = [5,4,10,7,5]return = [3,4]

Choosing departure index 3 and return index 4 gives a total cost of departing[3] + returning[4] = 3 + 5 = 8, which is the minimum possible total.

More Meta Onsite Interview questions

  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026
  • Maximum Stock Profit with Transaction LimitsONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Minimize Total Weight After HalvingAmazon · ONSITE INTERVIEW
  • Capacity to Ship Packages Within DaysMicrosoft · OA · ONSITE INTERVIEWMicrosoft interview questions
  • Gas StationeBay · ONSITE INTERVIEWeBay interview questions
  • Make an Array Non-Decreasing With One ModificationGoogle · ONSITE INTERVIEWGoogle interview questions
  • Wizard Scroll Allocation StrategyJane Street · ONSITE INTERVIEWJane Street interview questions
  • Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
  • Maximize Monsters DefeatedSalesforce · ONSITE INTERVIEWSalesforce interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int[] planMinimumCostRoundTrip(int[] departing, int[] returning) {
        // write your code here
    }
}
Checking account…