Interview Question

Software Engineer Interview

-Palo Alto, CA


Write a function to find the angle between the minute and hour hand in an analog clock.


Interview Answer

1 Answer


Convert minute to hour hand by multiplying with 1/5. Now both hands represent hours, 6 hours difference means 180 degrees, so 30 degrees per hour. We now need to find the hour difference between the hands. Check for time overflow (12 midnight) by taking the smaller of the two hands and adding 12 and then comparing to find the smallest hour difference between the hands. Finally, multiply the hour difference by 30 to obtain the angle between the hands.

Luca on

Add Answers or Comments

To comment on this, Sign In or Sign Up.