Angle Between Hands of a Clock - Problem

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

The angle should be calculated as a positive floating-point number. Answers within 10^-5 of the actual value will be accepted as correct.

Note: The hour hand moves continuously as minutes pass, not in discrete jumps.

Input & Output

Example 1 — Basic Case
$ Input: hour = 12, minutes = 30
Output: 165.0
💡 Note: At 12:30, minute hand points to 6 (180°), hour hand is halfway between 12 and 1 (15°). Angle = |180° - 15°| = 165°
Example 2 — Perfect Alignment
$ Input: hour = 3, minutes = 0
Output: 90.0
💡 Note: At 3:00, minute hand points to 12 (0°), hour hand points to 3 (90°). Angle = |90° - 0°| = 90°
Example 3 — Obtuse Angle Case
$ Input: hour = 3, minutes = 30
Output: 75.0
💡 Note: At 3:30, minute hand at 180°, hour hand at 105° (3×30° + 30×0.5°). Angle = |180° - 105°| = 75°

Constraints

  • 1 ≤ hour ≤ 12
  • 0 ≤ minutes ≤ 59

Visualization

Tap to expand
Clock Angle Problem: Finding the Smaller Angle12369Input: 3:00Formulas:Minute: minutes × 6°Hour: (hour % 12) × 30° + minutes × 0.5°Angle: min(|h-m|, 360°-|h-m|)12369Output: 90.0°
Understanding the Visualization
1
Input
Given hour and minutes (e.g., 3:15)
2
Calculate
Find each hand's angle from 12 o'clock position
3
Output
Return the smaller of two possible angles
Key Takeaway
🎯 Key Insight: Clock hands move at constant rates, making this a pure mathematical calculation problem
Asked in
Amazon 15 Microsoft 12 Apple 8
28.0K Views
Medium Frequency
~15 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen