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.
Example 1:
Input: hour = 12, minutes = 30
Output: 165
Approach:-
Code
public double angleClock(int hour, int minutes) {
int oneMinAngle = 6;
int oneHourAngle = 30;
double minuteAngle = minutes * oneMinAngle;
double hourAngle = ((hour%12)+minutes/60.0) * oneHourAngle;
doubel diff = Math.abs(hourAngle - minuteAngle);
return Math.min(diff, 360-diff);
}
Time complexity - O(1) Space complexity - O(1)