Amazon Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
find the angle bvetween the hands of a clock....
if "H" is the hours and "M" is the mins...then angle can be directly obtained by
ANGLE = 30H - (11/2)M
For example...when da time is 9:30...angle is
30*9 - (11/2)*30 = 270-165=105 degrees..
hope dat was useful.....
Let time be given as H:M where H is Hours and M is Minutes.
Angle covered by Hour hand in covering H hours = (H%12)*30 degrees
Additional angle covered by Hour hand in covering M minutes = (M%60)/2 degrees
Angle covered by Minute hand= (M%60)*6 degrees
So difference between them
abs( (H%12)*30 + (M%60)/2 - (M%60)*6 )
==> abs( (H%12)*30 - ((M%60)*11)/2 ) degrees
suppose `hour' is in [0..11]
and `min' is in [0..59]
we do not take seconds into account for simplicity
- pavel.em October 18, 2011