AmbiguousWatch
TCO07 Sponsor 1 · 2007-03-07 · by Mike Mirzayanov
Problem Statement
You have a watch with only an hour hand and a minute hand. The watch is a round 12-hour watch. Both hands move continuously. Both hands have the same length and are indistinguishable, so at certain moments, the time displayed is ambiguous. A time is considered ambiguous if there exists a different time at which the hands appear to have the same positions. For example, the time moment on the picture is ambiguous. At this moment, you would not be able to tell if it was a little past 00:05, or a little past 01:00.
You are given two times in the form "HH:MM" (quotes for clarity), where 00 <= HH < 12, and 00 <= MM < 60. Return the number of ambiguous moments between startTime and finishTime, inclusive. The times represented by startTime and finishTime are in the same half of the day.
Constraints
- startTime and finishTime will have the form "HH:MM" (quotes for clarity), where 00 <= HH < 12, 00 <= MM < 60.
- startTime must be earlier than or the same as finishTime (in the same half of the day).
"00:00" "00:00" Returns: 0
This moment is not ambiguous.
"00:05" "00:06" Returns: 1
There is one ambiguous moment in this time range. At that moment, you would not be able to tell if it was a little past 00:05, or a little past 01:00.
"00:00" "01:00" Returns: 11
"00:00" "11:59" Returns: 132
"03:21" "10:54" Returns: 84
Submissions are judged against all 107 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AmbiguousWatch with a public method int howMany(string startTime, string finishTime) · 107 test cases · 2 s / 256 MB per case