1436. Clock Hands Gap
An analogue wall clock has an hour hand and a minute hand, and both move continuously: the minute hand advances with the seconds, and the hour hand advances with the minutes and seconds. The clock shows the time hour:minute:second, where hour is given on a 24-hour scale, so use hour mod 12 for the hand position. Return the smaller of the two angles between the hands, in degrees, as a double between 0 and 180 inclusive. Answers within an absolute error of 1e-6 are accepted. Use O(1) time and space.
Example 1
- Input:
- hour = 3, minute = 0, second = 0
- Output:
- 90
- Explanation:
At 3:00:00 the hands are a quarter turn apart, which is 90 degrees.
Example 2
- Input:
- hour = 3, minute = 15, second = 0
- Output:
- 7.5
- Explanation:
At 3:15:00 the minute hand is at 90 degrees and the hour hand at 97.5 degrees, a gap of 7.5.
Constraints
0 ≤ hour ≤ 23
0 ≤ minute ≤ 59
0 ≤ second ≤ 59
Answers within an absolute error of 1e-6 are accepted.
How this problem is judged
- Answers
- Numbers are accepted within a tolerance of 1.0E-6: |answer - expected| <= 1.0E-6 x max(1, |expected|).
- Tolerance
0.000001
Expected complexity
- Time
- O(1)
- Space
- O(1)