This problem is known as Clock angle problem where we need to find angle between hands of an analog clock at a given time.
Input: h = 12:00 m = 30.00 Output: 165 degree Input: h = 3.00 m = 30.00 Output: 75 degree
The idea is to take 12:00 (h = 12, m = 0) as a reference. Following are detailed steps.
1. Calculate the angle made by hour hand with respect to 12:00 in h hours and m minutes.
2. Calculate the angle made by minute hand with respect to 12:00 in h hours and m minutes.
3. The difference between the two angles is the angle between the two hands.
How to calculate the two angles with respect to 12:00?
The minute hand moves 360 degrees in 60 minute(or 6 degrees in one minute) and hour hand moves 360 degrees in 12 hours(or 0.5 degrees in 1 minute). In h hours and m minutes, the minute hand would move (h*60 + m)*6 and hour hand would move (h*60 + m)*0.5.
Time Complexity: O(1)
Exercise: Find all times when hour and minute hands get superimposed.
This article is contributed by Ashish Bansal. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Time when minute hand and hour hand coincide
- Distance between end points of Hour and minute hand at given time
- Distance traveled by Hour and Minute hand in given Time interval
- Nth angle of a Polygon whose initial angle and per angle increment is given
- Program to calculate angle on circumference subtended by the chord when the central angle subtended by the chord is given
- Maximum time such that absolute difference between hour and minute lies in given range
- Angle between a chord and a tangent when angle in the alternate segment is given
- Area of Triangle using Side-Angle-Side (length of two sides and the included angle)
- Angle subtended by the chord when the angle subtended by another chord of same length is given
- Exterior angle of a cyclic quadrilateral when the opposite interior angle is given
- Angle subtended by the chord to center of the circle when the angle subtended by the another equal chord of a congruent circle is given
- Angle between two Planes in 3D
- Angle between 3 given vertices in a n-sided regular polygon
- Angle between a Pair of Lines in 3D
- Time taken per hour for stoppage of Car
- Program to find the Interior and Exterior Angle of a Regular Polygon
- Find other two sides and angles of a right angle triangle
- Length of the chord of the circle whose radius and the angle subtended at the center by the chord is given
- Find the area of rhombus from given Angle and Side length
- Length of diagonals of a Rhombus using length of Side and vertex Angle