Find the Smaller Angle Between Clock Hands
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
## Problem
Given an hour and minute on a 12-hour analog clock, return the smaller angle in
degrees between the hour hand and the minute hand. The hour hand moves
continuously as minutes pass; it does not remain fixed on an hour mark.
### Constraints & Assumptions
- `1 <= hour <= 12`.
- `0 <= minutes <= 59`.
- The answer is between 0 and 180 degrees inclusive.
- Use ordinary real-number arithmetic; seconds are zero.
### Clarifications
- Treat 12 as position zero for angular calculations.
- The hour hand advances 0.5 degrees per minute.
- Return the smaller of the direct separation and its complement around 360 degrees.
### Examples
```text
hour = 12, minutes = 30 -> 165.0
hour = 3, minutes = 30 -> 75.0
hour = 6, minutes = 0 -> 180.0
```
### Hints
```hint Compute absolute positions
Express both hands as angles clockwise from 12 o'clock.
```
```hint Choose the shorter arc
An absolute difference above 180 degrees is not the smaller separation.
```
Overview: Find the smaller angle between analog clock hands for a given hour and minute. Account for the hour hand's continuous half-degree movement per minute, normalize 12 to zero, and compare the direct separation with its complement around the clock.
Read the full Amazon Software Engineer interview experience this question came from
Given an hour and minute on a 12-hour analog clock with seconds equal to zero, return the smaller angle in degrees between the hour and minute hands. Treat 12 as angular position zero. The hour hand moves continuously by 0.5 degrees per minute, while the minute hand moves by 6 degrees per minute. Return the smaller of the direct separation and its complement around 360 degrees.
Constraints
- 1 <= hour <= 12.
- 0 <= minutes <= 59.
- Seconds are zero.
- The answer is between 0 and 180 degrees inclusive.
- Use ordinary real-number arithmetic.
Examples
Input: (12, 30)
Expected Output: 165.0
Explanation: At 12:30 the hour hand has advanced 15 degrees while the minute hand is at 180 degrees.
Input: (3, 30)
Expected Output: 75.0
Explanation: The hand positions are 105 and 180 degrees.
Hints
- Compute both hand positions clockwise from twelve.
- If the direct separation exceeds 180 degrees, use its complement.