Microsoft Interview Question

Brain Teaser #2 - Implement an algorithm in pseudo-code that outputs the angle between the hour hand and minute hand of an ordinary clock at any moment in time. (You are not allowed to hardcode anything. The algorithm must use formulas that you come up with yourself to translate the hours to degrees and the same for the minutes). For example, if the minute hand is exactly at 12, you cannot hardcode 12 = 0 degrees.

Interview Answer

Anonymous

Sep 7, 2011

Hour hand moves 360 degrees in 12 hours (720 minutes). So it moves 0.5 degrees per minute. So for time 3:20, hour hand would have moved (3 * 60 + 20) minutes * 0.5 degrees per minute = 100 degrees Minute hand moves 360 degrees in 60 minutes. That is, 6 degrees per minute. For 3:20, minute hand would have moved 20 minutes * 6 degrees per minute = 120 degrees. Difference = 120 - 100 = 20 degrees

1