This post is completed by 1 user

  • 1
Add to List
Beginner

119. Clock Angle Problem

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 hands meet, take it as reference.
  • The angle between hand and minute = angle of hour hand ~ angle of the 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 the given time is h hours and m mins, the hour hand will move (h*60+m)*0.5 and the minute hand will move 6*m
 

Output:

112.5
75.0
66.5