Practice/Microsoft/Leetcode 1344. Angle Between Hands of a Clock
CodingMust
Given the current time in hours and minutes on a 12-hour analog clock, calculate the smaller angle in degrees between the hour hand and the minute hand.
Remember that clock hands move continuously, not in discrete jumps. The hour hand gradually shifts as minutes pass, and you need to account for this continuous movement when computing its position.
Return the angle as a decimal number. The result should always be the smaller of the two possible angles between the hands (meaning it will never exceed 180 degrees).
1 <= hour <= 120 <= minutes <= 59Example 1:
Input: hour = 12, minutes = 0 Output: 0.0 Explanation: At exactly 12:00, both the hour and minute hands point straight up at the 12 position, so the angle between them is 0 degrees.
Example 2:
Input: hour = 3, minutes = 15 Output: 7.5 Explanation: The minute hand at 15 minutes points directly at the 3 (90 degrees from 12). The hour hand at 3:15 is 1/4 of the way from 3 to 4, which is at 97.5 degrees from 12. The difference is 7.5 degrees.
Example 3:
Input: hour = 9, minutes = 0 Output: 90.0 Explanation: At 9:00, the minute hand points at 12 (0 degrees) and the hour hand points at 9 (270 degrees from 12). The angle between them going clockwise from minute to hour is 270 degrees, but the smaller angle going the other direction is 90 degrees.
Example 4:
Input: hour = 6, minutes = 0 Output: 180.0 Explanation: At 6:00, the hands point in exactly opposite directions, creating a straight line with 180 degrees between them.