[Meta] FULLTIME PHONE SCREEN 2025-02-05

Problem Statement

You are given two arrays:

  • departing which represents the cost of departing flights at each time index.
  • returning which represents the cost of returning flights at each time index.

The index represents the time of departure or return. The goal is to find the minimum round-trip cost, where a returning flight can only be taken at a time later than the departing flight (i.e., if departing at time i, the return flight must be from time (i+1) onwards).

Example

Input

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

Output

2

Explanation

  • If we depart at time 0 (cost 1), we must return at time ≥ 1. The available return costs are [3, 2, 1], and the best option is at time 3 with cost 1.
  • Round-trip cost = 1 (depart) + 1 (return) = 2.
  • This is the minimum possible cost.

Constraints

  • Solve the problem in O(n) time complexity.

我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。

We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.

Leave a Reply

Your email address will not be published. Required fields are marked *