# The Clock Angle

> Two hands. One gap. One number.

Canonical URL: <https://datadriven.io/problems/the_clock_angle>

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given hour (1..12) and minute (0..59), return the smaller angle in degrees between the hour and minute hands on a standard analog clock. The hour hand moves 0.5 degrees per minute; the minute hand moves 6 degrees per minute.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **mathematical reasoning under constraints**: computing angles from continuous hand positions on a clock. It probes whether a candidate recognizes that the hour hand moves continuously with minutes, not in discrete jumps.

> **Trick to Solving**
>
> The hour hand moves 0.5 degrees per minute (30 degrees per hour / 60 minutes). The minute hand moves 6 degrees per minute. Compute both absolute positions, take the difference, and return the smaller of the two possible angles.

---

### Break down the requirements

#### Step 1: Compute the minute hand angle

Each minute moves the hand 6 degrees: `minute * 6`.

#### Step 2: Compute the hour hand angle

Each hour is 30 degrees, plus 0.5 degrees per minute: `(hour % 12) * 30 + minute * 0.5`.

#### Step 3: Return the smaller angle

Take the absolute difference, then return `min(diff, 360 - diff)` since the clock is circular.

---

### The solution

**Continuous hand position calculation**

```python
def clock_angle(hour: int, minute: int) -> float:
    minute_angle = minute * 6
    hour_angle = (hour % 12) * 30 + minute * 0.5
    diff = abs(hour_angle - minute_angle)
    smaller_angle = min(diff, 360 - diff)
    return smaller_angle
```

> **Time and Space Complexity**
>
> **Time:** O(1). Pure arithmetic with no iteration.
> 
> **Space:** O(1). Only scalar variables.

> **Interviewers Watch For**
>
> Whether you account for the hour hand's continuous movement. Treating hour 3 as exactly 90 degrees regardless of minutes is the most common mistake.

> **Common Pitfall**
>
> Forgetting `hour % 12`. When hour is 12, the hand is at the 0-degree position, not at 360.

---

## Common follow-up questions

- What if the input uses 24-hour format? _(Tests whether you apply `% 12` correctly for values like 13 or 23.)_
- At what times are the hands exactly opposite (180 degrees)? _(Tests reverse-engineering the formula to solve for minute given a target angle.)_
- How would you handle seconds for sub-degree precision? _(Tests extending the formula: seconds add 0.1 degrees to the minute hand and ~0.0083 to the hour hand.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/the_clock_angle)
- [Python Interview Questions](https://datadriven.io/python-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.