Clock Angle Between Hour and Minute Hands
Problem Given a time on an analog clock, such as 3:15, compute the angle between the hour hand and the minute hand.
Input / Output
- Input: two integers,
hourandminutes - Output: the angle in degrees between the two hands — conventionally the smaller of the two, so always in [0, 180]
Constraints
- Hours 0-11 (or 1-12 — worth clarifying), minutes 0-59
- Both hands move continuously: the hour hand does not jump on the hour, it drifts as the minutes pass. This is the detail the question actually tests
- The answer can be fractional, in multiples of 0.5 degrees
Example
- At 3:15 the minute hand points exactly at the 3 mark (90 degrees), while the hour hand has moved a quarter of the way from 3 to 4, i.e. 7.5 degrees past the 3 mark → angle = 7.5 degrees
- At 12:00 the hands overlap → 0 degrees
asked …