Problem · Array

Space Station Shuttle Missions

Learn this problem
EasyTiktok logoTiktokINTERNOA
See Tiktok hiring insights

Problem statement

A space-station network has two hubs, Alpha and Beta. Shuttle departures from Alpha to Beta are given by the sorted integer array alpha2beta, and departures from Beta to Alpha are given by the sorted integer array beta2alpha.

Every shuttle trip takes exactly 100 time units. Your journey starts at Alpha at time 0.

Complete missions missions. Each mission consists of traveling from Alpha to Beta and then returning from Beta to Alpha. For every leg, take the earliest shuttle whose departure time is at or after your arrival at that hub.

Return the time when all missions are complete. The schedules guarantee that every required leg can be completed.

Function

completeShuttleMissions(alpha2beta: int[], beta2alpha: int[], missions: int) → int

Examples

Example 1

alpha2beta = [0,200,500]beta2alpha = [99,210,450]missions = 1return = 310

Take the Alpha-to-Beta shuttle at time 0 and arrive at Beta at time 100. The earliest available return shuttle departs at time 210, so the mission finishes at Alpha at time 310.

Example 2

alpha2beta = [0,300,700]beta2alpha = [150,500,900]missions = 2return = 600

The first mission uses departures 0 and 150, finishing at time 250. The second uses departures 300 and 500, finishing at time 600.

Example 3

alpha2beta = [100,400]beta2alpha = [200,500]missions = 2return = 600

After departing Alpha at 100, you arrive at Beta exactly when the shuttle at 200 departs. The second mission similarly uses departures 400 and 500, so all missions finish at time 600.

Constraints

  • alpha2beta and beta2alpha are sorted arrays of integer departure times.
  • Every Alpha-to-Beta and Beta-to-Alpha trip takes exactly 100 time units.
  • For every required leg, the corresponding schedule contains an available departure at or after the current time.

More Tiktok problems

drafts saved locally
public int completeShuttleMissions(int[] alpha2beta, int[] beta2alpha, int missions) {
    // Write your code here.
}
alpha2beta[0,200,500]
beta2alpha[99,210,450]
missions1
expected310
checking account