Clock Angle Problem | Algorithms
Objective: Find the Angle between hour hand and minute hand at the given time.
Example:
Time : 12:45 Input : hour = 12, Minute = 45 Output : 112.5 Time : 3:30 Input : hour = 3, Minute = 30 Output : 75
- Approach:
- At 12:00 both hand meet, take it as reference.
- Angle between hand and minute = angle of hour hand ~ angle of minute hand.
- return minimum(angle, 360-angle)
- hour hand moves 360 in 12 hours => 360/12 = 30 degree in one hour or 0.5 degree in 1 min
- Minute hand moves 360 in 60 mins => 360/60 = 6 degree in one min
- So if given time is h hours and m mins, hour hand will move (h*60+m)*0.5 and minute hand will move 6*m
Read full article from Clock Angle Problem | Algorithms
No comments:
Post a Comment