Clock Hand Angle with Subsecond Precision
Problem statement
Given a valid time on a 12-hour analog clock, return the smaller angle in degrees between the hour hand and the minute hand.
The input time uses one of these forms:
HH:MMHH:MM:SSHH:MM:SS.mmm
Both hands move continuously. Seconds and milliseconds therefore affect both the minute-hand and hour-hand positions.
Function
smallerClockAngle(time: String) → doubleExamples
Example 1
time = "03:45"return = 157.5At 03:45, the minute hand is at 270 degrees and the hour hand is at 112.5 degrees. Their smaller separation is 157.5 degrees.
Example 2
time = "12:00:30"return = 2.75After 30 seconds, the minute hand has moved 3 degrees and the hour hand has moved 0.25 degrees, so the smaller angle is 2.75 degrees.
Example 3
time = "06:00:00.500"return = 179.9541666667Half a second after 06:00, both hands have moved continuously. Their smaller separation is approximately 179.9541666667 degrees.
Constraints
timeis a valid zero-padded 12-hour clock time in one of the three documented formats.01 <= HH <= 12,00 <= MM, SS <= 59, and000 <= mmm <= 999.- Missing seconds or milliseconds are treated as
0. - Return a value in the closed range
[0, 180]. Answers within10^-6of the correct value are accepted.