FastPrepBuses in a Bustling Town 🚌

Buses in a Bustling Town 🚌

Meta logoMeta● EasyFULLTIMEOA
Learn

Problem statement

In a bustling town where buses shuttle passengers throughout the day, the schedule of bus departures is meticulously recorded. Imagine you're standing at the bus stop, checking the time on your watch. You want to know how long ago the last bus departed. But if the day hasn't started yet and the first bus hasn't left, you're out of luck and receive a signal of -1.

Your task is to determine, from the listed departure times and the current time, how many minutes have passed since the last bus departed. Remember, if a bus is scheduled to leave exactly at the current time, it hasn't departed yet.

Function

bustlingTownBuses(timeTable: String[], moment: String) β†’ int

Examples

Example 1

timeTable = ["12:30", "14:00", "19:55"]moment = "14:30"return = 30

The present moment -> "14:30". The very last bus in the town departed at "14:00", so we can return 30 (literally 30 mins ago) P.S. For original prompt, pls refer to source img.

Example 2

timeTable = ["00:00", "14:00", "19:55"]moment = "00:00"return = -1

Unfortunately 😒, there is not buses departed before "00:00" (the bus was supposed to depart at "00:00" hasn't departed yet), so return -1; P.S. For original prompt, pls refer to source image.

Example 3

timeTable = ["12:30", "14:00", "19:55"]moment = "14:00"return = 90

The present moment is "14:00". And the most recent bus departed at "12:30" (the bus was supposed to go at "14:00" hasn't departed yet), so we return 90. P.S. For original prompt, pls refer to source image.

Constraints

  • Uknown for now

More Meta problems

See Meta hiring insights
public int bustlingTownBuses(String[] timeTable, String moment) {
  // write your code here
}
timeTable["12:30", "14:00", "19:55"]
moment"14:30"
expected30
Checking account…