Minimum Valid Round-Trip Fare
Updated
Problem statement
Two arrays give ticket fares by day: departing[i] is the fare to leave on day i, and returning[j] is the fare to return on day j. Choose a departure day i and a return day j with j >= i. Return the minimum possible total fare departing[i] + returning[j].
For this practice version, the arrays may have different lengths. Their index zero refers to the same day, and returning on the departure day is valid.
Function
minimumValidRoundTripFare(departing: int[], returning: int[]) → intExamples
Example 1
departing = [10,3,10,9,3]returning = [4,20,6,7,10]return = 9Leave on day 1 for 3 and return on day 2 for 6. No valid pair costs less than 3 + 6 = 9.
Example 2
departing = [1,100]returning = [1,100]return = 2Both tickets may be on day 0, for a total fare of 1 + 1 = 2.
Example 3
departing = [8,2]returning = [5,20,1]return = 3Leave on day 1 for 2 and return on day 2 for 1. The return array extends beyond the departure array.
Constraints
1 <= departing.length, returning.length <= 100000.0 <= departing[i], returning[j] <= 1000000000.- The arrays may have different lengths.
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Jump GamePaytm · PHONE SCREENPaytm 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
- Remove the Fewest Magic BeansThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Capacity to Ship Packages Within DaysMicrosoft · OA · ONSITE INTERVIEWMicrosoft interview questions
- Gas Station CircuitAngel One · PHONE SCREEN
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