Hi~ The other question asked together was LC863 :) Thanks to the OP! Wish OP all the best!
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). For example, departing = [1,2,3,4] and returning = [4,3,2,1], the minimum cost for round trip will be 2 i.e departing[0] + returning[3]. Solve this in O(n) time.
Examples
01 · Example 1
departing = [1, 2, 3, 4] returning = [4, 3, 2, 1] return = 2
😱
Constraints
🤓More Meta problems
- Merge Three Sorted ArraysPHONE SCREEN · Seen May 2026
- Diagonal Traverse (for E4 ;)PHONE SCREEN · Seen Mar 2025
- Find Peak ElementPHONE SCREEN · Seen Mar 2025
- Find Pair Closest to K (for E5 :)PHONE SCREEN · Seen Feb 2025
- Max Consecutive Ones III (for E5 :)PHONE SCREEN · Seen Feb 2025
- Nested List Weight Sum (for E4)PHONE SCREEN · Seen Feb 2025
- Sliding Window Average (Meta Canada, E4/E5 :)PHONE SCREEN · Seen Dec 2024
- Build Blocks and Obstacles on a Number LineSeen Oct 2024
public int getMinimumRoundTripCost(int[] departing, int[] returning) {
// write your code here
}
departing[1, 2, 3, 4]
returning[4, 3, 2, 1]
expected2
sign in to submit