Find the smaller angle between the hour and minute hands of a clock

Quick Overview

Given an hour and a minute on a 12-hour analog clock, return the smaller angle in degrees between the hour and minute hands. The problem tests turning a time into hand positions, accounting for the hour hand moving with the minutes, and choosing the smaller of the two angles between the hands.

Find the smaller angle between the hour and minute hands of a clock

Company: Tesla

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given two integers `hour` and `minutes`, return the **smaller angle** (in degrees) formed between the hour and minute hands of an analog clock. The answer should be a floating point number. Answers within `10⁻⁵` of the actual answer will be accepted. ### Function Signature ```python def angle_clock(hour: int, minutes: int) -> float: ``` ### Rules - The clock is a 12-hour analog clock with no seconds hand. - The hour hand moves continuously as the minutes pass, so at 12:30 it sits halfway between 12 and 1. - Of the two angles between the hands, return the smaller one, so the result is between 0 and 180 inclusive. ### Constraints - `1 <= hour <= 12` - `0 <= minutes <= 59` - Answers within `10⁻⁵` of the actual answer are accepted. ### Examples ```text Input: hour = 12, minutes = 30 Output: 165 ``` At 12:30, the minute hand is at 180 degrees and the hour hand is at 15 degrees. The angle between them is 165 degrees. ```text Input: hour = 3, minutes = 30 Output: 75 ``` At 3:30, the minute hand is at 180 degrees and the hour hand is at 105 degrees. The angle between them is 75 degrees.

Overview: Given an hour and a minute on a 12-hour analog clock, return the smaller angle in degrees between the hour and minute hands. The problem tests turning a time into hand positions, accounting for the hour hand moving with the minutes, and choosing the smaller of the two angles between the hands.

Tesla logo
Tesla
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given two integers hour and minutes, return the smaller angle (in degrees) formed between the hour and minute hands of an analog clock.

The answer should be a floating point number. Answers within 10⁻⁵ of the actual answer will be accepted.

Function Signature

def angle_clock(hour: int, minutes: int) -> float:

Rules

  • The clock is a 12-hour analog clock with no seconds hand.
  • The hour hand moves continuously as the minutes pass, so at 12:30 it sits halfway between 12 and 1.
  • Of the two angles between the hands, return the smaller one, so the result is between 0 and 180 inclusive.

Constraints

  • 1 <= hour <= 12
  • 0 <= minutes <= 59
  • Answers within 10⁻⁵ of the actual answer are accepted.

Examples

Input: hour = 12, minutes = 30
Output: 165

At 12:30, the minute hand is at 180 degrees and the hour hand is at 15 degrees. The angle between them is 165 degrees.

Input: hour = 3, minutes = 30
Output: 75

At 3:30, the minute hand is at 180 degrees and the hour hand is at 105 degrees. The angle between them is 75 degrees.