Given two numbers **H** and **M** which denotes the length of the hour and minute hand and two time intervals(say **T1 & T2**) in form of **HH:MM**, the task is to find the distance travelled by hour hand and minute hand between time **T1 and T2**.

**Examples:**

Input:H = 5, M = 7, T1 = “1:30”, T2 = “10:50”

Output:

Distance travelled by minute hand: 410.50144006906635

Distance travelled by hour hand: 24.434609527920614

Input:H = 4, M = 5, T1 = “1:30”, T2 = “10:50”

Output:

Distance travelled by minute hand: 293.21531433504737

Distance travelled by hour hand: 19.54768762233649

**Approach:**

- Find the difference between the two time intervals T1 and T2 by using the approach discussed in this article.
- Change the time duration obtained above into minutes as:
Total Minutes = hours * 60 + minutes

- Since minute hand covers one rotation in 60 minutes therefore, number of rotations covered by minute hand(say
**rm**) is given by - Since hour hand covers one rotation in 60*12 = 720 minutes therefore, number of rotations covered by hour hand(say
**rh**) is given by - The total distance traverse by the hour hand is given by
- The total distance traverse by the minute hand is given by

Below is the implementation of the above approach:

## Python

`# Python program for the above approach ` ` ` `import` `math ` ` ` `# Function to remove ':' and convert ` `# it into an integer ` `def` `removeColon(s): ` ` ` `if` `(` `len` `(s) ` `=` `=` `4` `): ` ` ` `s ` `=` `s[:` `1` `]` `+` `s[` `2` `:] ` ` ` ` ` `if` `(` `len` `(s) ` `=` `=` `5` `): ` ` ` `s ` `=` `s[:` `2` `]` `+` `s[` `3` `:] ` ` ` ` ` `return` `int` `(s) ` ` ` `# function which find the difference ` `# between time interval ` `def` `diff(s1, s2): ` ` ` ` ` `# Change string as 2:21 to 221 ` ` ` `time1 ` `=` `removeColon(s1) ` ` ` `time2 ` `=` `removeColon(s2) ` ` ` ` ` `# Difference between hours ` ` ` `hourDiff ` `=` `time2 ` `/` `/` `100` `-` `time1 ` `/` `/` `100` `-` `1` `; ` ` ` ` ` `# Difference between minutes ` ` ` `minDiff ` `=` `time2 ` `%` `100` `+` `(` `60` `-` `time1 ` `%` `100` `) ` ` ` ` ` `if` `(minDiff >` `=` `60` `): ` ` ` `hourDiff` `+` `=` `1` ` ` `minDiff ` `=` `minDiff ` `-` `60` ` ` ` ` `# Convert answer again in string ` ` ` `# with ':' ` ` ` `res ` `=` `str` `(hourDiff) ` `+` `':'` `+` `str` `(minDiff) ` ` ` `return` `res ` ` ` `# Function for finding the distance travelled ` `# by minute hand and hour hand ` `def` `disTravel(T1, T2, M, H): ` ` ` ` ` `# Find the duration between these time ` ` ` `dur ` `=` `diff(T1, T2) ` ` ` ` ` `# Remove colom from the dur and ` ` ` `# convert in int ` ` ` `s ` `=` `removeColon(dur) ` ` ` ` ` `# Convert the time in to minute ` ` ` `# hour * 60 + min ` ` ` `totalMinute ` `=` `(s` `/` `/` `100` `)` `*` `60` `+` `s ` `%` `100` ` ` ` ` `# Count min hand rotation ` ` ` `rm ` `=` `totalMinute ` `/` `60` `; ` ` ` ` ` `# Count hour hand rotation ` ` ` `rh ` `=` `totalMinute ` `/` `720` `; ` ` ` ` ` `# Compute distance traveled by min hand ` ` ` `minuteDistance ` `=` `rm ` `*` `2` `*` `math.pi ` `*` `M; ` ` ` ` ` `# Compute distance traveled by hour hand ` ` ` `hourDistance ` `=` `rh ` `*` `2` `*` `math.pi ` `*` `H; ` ` ` ` ` `return` `minuteDistance, hourDistance ` ` ` ` ` `# Driver Code ` ` ` `# Given Time Intervals ` `T1 ` `=` `"1:30"` `T2 ` `=` `"10:50"` ` ` `# Given hour and minute hand length ` `H ` `=` `5` `M ` `=` `7` ` ` `# Function Call ` `minuteDistance, hourDistance ` `=` `disTravel(T1, T2, M, H) ` ` ` `# Print the distance traveled by minute ` `# and hour hand ` `print` `(` `"Distance traveled by minute hand: "` ` ` `,minuteDistance) ` `print` `(` `"Distance traveled by hour hand: "` ` ` `,hourDistance ) ` |

*chevron_right*

*filter_none*

**Output:**

Distance traveled by minute hand: 410.50144006906635 Distance traveled by hour hand: 24.434609527920614

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.

## Recommended Posts:

- Time when minute hand and hour hand coincide
- Calculate the angle between hour hand and minute hand
- Distance between end points of Hour and minute hand at given time
- Maximum time such that absolute difference between hour and minute lies in given range
- Calculate the Square of Euclidean Distance Traveled based on given conditions
- Distance Traveled by Two Trains together in the same Direction
- Time taken per hour for stoppage of Car
- Distance of chord from center when distance between center and another equal length chord is given
- Count paths with distance equal to Manhattan distance
- Max occurring divisor in an interval
- Count of available non-overlapping intervals to be inserted to make interval [0, R]
- Calculate speed, distance and time
- Time until distance gets equal to X between two objects moving in opposite direction
- Find the radii of the circles which are lined in a row, and distance between the centers of first and last circle is given
- Find the side of the squares which are lined in a row, and distance between the centers of first and last square is given
- Minimum time to reach a point with +t and -t moves at time t
- Find points at a given distance on a line of given slope
- Find the Jaccard Index and Jaccard Distance between the two given sets
- Distance between centers of two intersecting circles if the radii and common chord length is given
- Minimum distance between the maximum and minimum element of a given Array

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.