Problem Β· String
Buses in a Bustling Town π
Learn this problemProblem 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) β intExamples
Example 1
timeTable = ["12:30", "14:00", "19:55"]moment = "14:30"return = 30The 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 = -1Unfortunately π’, 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 = 90The 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 nowMore Meta problems
- Plan a Minimum-Cost Round TripONSITE INTERVIEW Β· Seen Jul 2026
- Merge Three Sorted ArraysPHONE SCREEN Β· Seen May 2026
- Highest Rating Price RatioOA Β· Seen Mar 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
- Get Minimum Round Trip Cost (: for E4 && E5 :)PHONE SCREEN Β· Seen Feb 2025
- Max Consecutive Ones III (for E5 :)PHONE SCREEN Β· Seen Feb 2025