Angle Between the Hands of a Clock

Understand and solve the interview question "Angle Between the Hands of a Clock."

Description

Given two numbers, hour and minutes we will return the smaller angle (in degrees) formed between the hour and the minute hands on a clock.

Let’s look at some examples to better understand this:

1 / 2
At hour = 3 and minutes = 60, angle = 75

Coding exercise

def clock_angle(hour, minutes):
# Write your code here
pass
Angle between the hands of a clock

Solution

The idea is to separately calculate the angles between the 0-minutes vertical line and each hand. The answer will be the difference that is found between the two angles.

Note: Black lines in the clock represent the 0-minutes vertical lines.

The minute hand points at 12 minutes on the clock while the hour hand points at 1 hour on the clock

Minute hand angle

Let’s start from the minute hand. The minute hand moves with 1 min intervals. At 1 min, the angle of the minute hand is . . Since the whole circle of the clock is equal to 360° degrees and 60 minutes, we estimated that the minute hand moves 1 min = 360° / 60 = 6° degree with each minute.

At 60 minutes, the angle of the clock is 360°, and at 1 minute the angle is 6°

Now, we can easily find an angle between the 0-minutes vertical line and a minute hand, using minutes_angle = minutes X 6°. ...

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.