#1344
Medium Algorithms Angle between hands of a clock
Math
64.4% acceptance
Feb 25, 2026
1373
248
Given two numbers, hour and minutes, return the smaller angle (in degrees) formed between the hour and the minute hand.
Answers within 10-5 of the actual value will be accepted as correct.
Solution
Rust
Time O(1)
Space O(1)
impl Solution {
pub fn angle_clock(hour: i32, minutes: i32) -> f64 {
let hour = hour % 12;
let minute_angle = minutes as f64 * 6.0;
let hour_angle = hour as f64 * 30.0 + minutes as f64 * 0.5;
let diff = (minute_angle - hour_angle).abs();
diff.min(360.0 - diff)
}
}