Using **Javascript**, together a software developer I"ll shot to price interview inquiry "**How many times a work a clock"s hands overlap?**" v the precise overlapping time of the clock"s hour hand and also minute hand.This tricky concern was inquiry by my manager to one of our intern university student.Later us learnt the this concern "How countless times carry out a clock"s hands overlap in a day?" is an interview concern asked for task applicants in Google.

You are watching: How many times do clock hands overlap in a day

Let"s an initial analyze the problem of overlapping clock"s hour and also minute hands.First set our imaginary clock come 12:00 midnight i m sorry is the starting time for the problems time period.

As you check out at start time once the period for calculation starts we have an overlapping problem for clock"s hour hand and also minute hand.

Now assume that the clock"s hour and minute hand overlap for the next time.The very first overlapping ~ 12:00 o"clock will happen in between 1 o"clock and also 2 o"clock.But we do not know the precise time right currently at this phase of the difficulty solution.

Let"s examine the above situtation now. Very first of all, clock"s hour hand only relocated from position 12 come a position in between 1 and 2. What is exciting for the equipment of this inteview question is that at the very same time period, the minute hand the the clock completed a full cycle starting from 12 to 12 and additionally traveled the same distance together hour hand at the overlapping time.

Here is a drawing displaying the case visually to help you know the hint for the equipment of "how numerous times a work a clock"s hands overlap?".

We have one basic mathematical equation because that this difficulty that will certainly lead united state to solution.The minute hand is 12 times much faster than the hour hand.If you think of the moment passing indigenous 12:00 o"clock to 1 o"clock, the minute hand travels 360 degrees. Meanwhile the hour hand travels 1/12 the 360 degrees.Or in a different thinking, in a specific time duration (t) minutes, the minute hand travel (360 * t) / 60 degreesBut in ~ the exact same time the hour hand only travels 1/12 of the degree: (360 * t) / (60 * 12) degrees.

An other equation originates from the happen hours. Each passing hour the minute hand completes a full cycle.Let"s say the the hour hand travel (n) degrees. For this reason we deserve to say at when they overlap each other the minute hand traveled (360 + n) levels at the same time as hour hand.

So we deserve to now say that while hour hand travel (n) degrees the minute hand will take trip (12*n) degrees.The an outcome that will certainly outcome native this additional equation with very first mathematical equation will be as follows:

12 * n = 360 + n

Of course 360 levels is true if only 1 hour has passed.If two hours passed, climate the formula will certainly be: 12 * n = 360*2 + nSo we have the right to re-formulate the equation together follows:

12 * n = 360 * h + n

Now replace n the level the hour hand traveled over time t, (360*t)/(60*12)

12 * (360*t)/(60*12) = 360 * h + (360*t)/(60*12)11 * (360*t)/(60*12) = 360 * h11 * t / 2 = 360 * h11 * t = 720 * h

For an initial hour we deserve to replace h through 1 and also we have the right to solve the equation for first overlap after ~ 12:00 o"clock

t = 720 /11 = 65,45 minutes

There is an other tricky conversion right here the decimal component of the time. We need to convert it come seconds.

0,45 minutes = 45/100 minutes = 45*60/100 seconds= 27 seconds

So the an initial overlap is at 65 minutes 27 seconds later on which means 1:05:27

Then we can continue calculation because that the second overlap the clock"s hands. This will occur between 2 o"clock and also 3 o"clock.This means minute hand that the clock will take trip 2 times complete circle and also plus the same amount as hour hand.

Now I desire to move all this calculations into listed below Javascript code

## Javascript Code

Here space some sample Javascript password calculating the times as soon as the clock"s hand overlap in a dayPlease note that the listed below Javascript code is detailed by Hilal �etinkaya, our intern student. Many thanks a lot because that her assist for the systems of this interesting problem.

There is a Javascript Loop framework to calculate each time the minute hand completes a complete cycle.Since in a work the sample from midnight till noon will certainly be exact same for the second half of the work (from noon it spins midnight), the Javascript loop is characterized for an essence variable starting from 0 to 11.

var t, n, temp1, temp2;var hour, minutes, seconds;for (t = 0; t n = 720 * t / 11;var n = Math.round(n * 100) / 100;hour = Math.floor(n / 60);minutes = Math.floor(n) % 60;temp1 = n * 100;temp2 = temp1 % 100;seconds = Math.floor((temp2 * 60) / 100);document.write( (t+1) + ". Time overlap wake up at " + hour + ":" + minute + ":" + secs + "");}

Code

Within the loop, each overlap condition is calculated making use of the mathematical equation discussed in vault section.For loop structure includes mod functions and Mart.floor() functions for converting the time in minutes to hours:minutes:seconds display format.

See more: How Much Is Yung Berg Worth, Yung Berg (Hitmaka) Net Worth

As you see in the output of this sample Javascript code, an initial overlap wake up at 00:00:00 o"clock.And the last overlap of clock"s hand will occur at 24:00:00To price the interview inquiry "How countless times a work a clock"s hands overlap?", first of all us should recognize if first overlap time the is the beginning time counts or not.I assume the we have the right to agree the start time is also one that the overlapping times in a day.So, below is the times count and clock"s hand overlap time within 24 hours:1. Time overlap wake up at 00:00:002. Time overlap occurs at 01:05:273. Time overlap occurs at 02:10:544. Time overlap occurs at 03:16:215. Time overlap occurs at 04:21:496. Time overlap occurs at 05:27:167. Time overlap wake up at 06:32:438. Time overlap occurs at 07:38:109. Time overlap wake up at 08:43:3810. Time overlap wake up at 09:49:0511. Time overlap occurs at 10:54:3212. Time overlap wake up at 12:00:0013. Time overlap occurs at 13:05:2714. Time overlap occurs at 14:10:5415. Time overlap wake up at 15:16:2116. Time overlap occurs at 16:21:4917. Time overlap wake up at 17:27:1618. Time overlap wake up at 18:32:4319. Time overlap occurs at 19:38:1020. Time overlap occurs at 20:43:3821. Time overlap occurs at 21:49:0522. Time overlap occurs at 22:54:3223. Time overlap wake up at 24:00:00 (since us count starting as among overlaps, this could be excluded)

As a result, if you counting the critical case, there are 23 times when a clock"s hour and also minute hand overlap in a day.If girlfriend exclude among the midnights, we can conclude the there room 22 times when a clock"s hand overlap in a day.