FastPrepWait Until the Next Shuttle

Wait Until the Next Shuttle

TikTok logoTikTok● EasyFULLTIMEOA
Learn

Problem statement

A theme park runs shuttles on a daily timetable. You are given shuttle_times, sorted in chronological order, and the current time current_time. Every time uses the 24-hour format HH:MM.

Find the earliest shuttle that has not left. A departure earlier than current_time has already left. For this exercise, assume a departure exactly at current_time is still available.

Return the waiting time as a string in HH:MM format, with two digits for both hours and minutes. If no shuttle remains today, return the string "-1". Do not wait for service on the next day.

For this exercise, assume the timetable may be empty and may contain duplicate departure times.

Function

nextShuttleWait(shuttle_times: String[], current_time: String) → String

Examples

Example 1

shuttle_times = ["12:30","14:00","19:55"]current_time = "14:30"return = "05:25"

The departures at 12:30 and 14:00 have already left. The next is 19:55. The difference from 14:30 is 325 minutes, or 05:25.

Example 2

shuttle_times = ["12:30","14:00","19:55"]current_time = "20:00"return = "-1"

At 20:00, every listed shuttle has already left. Return "-1".

Example 3

shuttle_times = ["12:30","14:00","19:55"]current_time = "14:00"return = "00:00"

The shuttle at 14:00 leaves at the current time and is still available. The wait is 00:00.

Constraints

  • For this exercise, assume 0 <= shuttle_times.length <=1440.
  • Every time string has exactly 5 characters in the form HH:MM.
  • The hour is from 00 through 23, and the minute is from 00 through 59.
  • shuttle_times is sorted in nondecreasing chronological order.

More TikTok problems

See TikTok hiring insights
Saved
class Solution {
    public String nextShuttleWait(String[] shuttle_times, String current_time) {
        // Return the waiting time or "-1".
        return "-1";
    }
}
shuttle_times["12:30","14:00","19:55"]
current_time"14:30"
expected"05:25"
Checking account…