![]() |
VOOZH | about |
Given four integers H, M, L1, and L2, which denotes the time as an hour and minutes in a Clock of 12-Hour format and L1 and L2 denotes the length of the hour hand and minute hand respectively. The task is to find the distance between the endpoints of the hour and minutes hand.
Examples:
Input: H = 3, M = 30, L1 = 3, L2 = 4
Output: 4.33499
Explanation:
At 3:30, distance between end point of hour hand and minute hand is 4.33499
Input: H = 10, M = 30, L1 = 3, L2 = 4
Output: 6.47898
Explanation:
At 10:30, distance between end point of hour hand and minute hand is 6.47898
Approach: The idea is to find the angle between the hour hand and minute hand at the given time and then the distance between the endpoints of the hour hand and minute hand can be computed with the help of the cosine formulae -
Distance Between End Points of the Hour and minute hand =
Below is the implementation of the above approach:
4.33499
Time complexity: O(logn) because sqrt function has been
Auxiliary space: O(1)