Problem 129918 · hard · Phase 01 Prerequisites & Setup

When the Clock Hands Meet

functions · strings · exact arithmetic · floor division · time formatting

The town hall has an ordinary analogue clock: the hour hand turns once every 12 hours, the minute hand once every hour, and both move smoothly. At 00:00 (midnight) they point the same way.

A photographer watches the clock from start to end, both given as 24-hour "HH:MM" strings. Both ends are included. If end is earlier than start, the watch runs past midnight into the next day; if they are equal, it lasts a single instant.

Write hands_meet(start, end) that returns a tuple (count, first): how many times during the watch the two hands point in exactly the same direction, and the first such moment as an "HH:MM:SS" string with the seconds rounded down. If they never meet, first is "".

Examples

Input:  start = "12:00", end = "13:05"
Output: (1, "12:00:00")
Explanation: the next meeting after 12:00 is at about 13:05:27, too late.

Input:  start = "13:05", end = "13:06"
Output: (1, "13:05:27")

Input:  start = "23:30", end = "00:30"
Output: (1, "00:00:00")

Input:  start = "00:00", end = "23:59"
Output: (22, "00:00:00")

Constraints

  • start and end are valid times from "00:00" to "23:59".

Goals

  • Turn a meeting condition into an equation with whole numbers
  • Count solutions in an interval without floats
  • Format a time with zero padding and handle a midnight wrap
Starting Python…