Ctrl K

Gap Between the Clock Hands

Medium
An ordinary round analogue clock shows hours hours and minutes minutes. The hour hand moves smoothly: it covers 30° per hour, so it shifts by half a degree every minute. Return the smaller of the two angles between the hour hand and the minute hand, in degrees. Answers within 10⁻⁵ of the exact value are accepted.
Example 1
hours=9, minutes=0 → 90.0

The hour hand is exactly on 9 and the minute hand on 12: a quarter turn apart, 90°.

Example 2
hours=6, minutes=20 → 70.0

The minute hand points at 120°. In 20 minutes the hour hand has moved 10° past 180°, to 190°. The gap is 70°.

Example 3
hours=12, minutes=50 → 85.0

The minute hand is at 300° and the hour hand at 25°. That is 275° one way, but only 360 − 275 = 85° the other way.

Constraints
  • 1 ≤ hours ≤ 12
  • 0 ≤ minutes ≤ 59
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAdding Digit Lists MediumBackwards Digits in 32 Bits MediumNumber in Roman Numerals MediumDivision Without Dividing MediumMultiplying Digit Strings Medium
loading Python…
Input
hours=9, minutes=0
Expected
90.0

Run checks the first 3 tests in your browser. Submit checks all 75 tests on the server, hidden ones included.