Using Javascript, together a software program developer I"ll try to answer interview question "How many times a job a clock"s hands overlap?" with the precise overlapping time of the clock"s hour hand and also minute hand.This tricky question was request by mine manager to one of our intern college student.Later us learnt the this inquiry "How plenty of times perform a clock"s hands overlap in a day?" is one interview question asked for task applicants in Google.

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


Let"s very first analyze the difficulty of overlapping clock"s hour and minute hands.First set our imaginary clock come 12:00 midnight i beg your pardon is the beginning time because that the difficulties time period.

*

As you see at start time once the duration for calculation start we have an overlapping problem for clock"s hour hand and also minute hand.

Now assume the the clock"s hour and minute hands overlap for the next time.The very first overlapping after 12:00 o"clock will certainly happen in between 1 o"clock and also 2 o"clock.But we do not recognize the precise time right currently at this stage of the problem solution.

*

Let"s research the above situtation now. An initial of all, clock"s hour hand only relocated from position 12 come a position between 1 and also 2. What is exciting for the solution of this inteview concern is the at the exact same time period, the minute hand the the clock perfect a complete cycle starting from 12 come 12 and additionally traveled the same distance as hour hand in ~ the overlapping time.

Here is a drawing displaying the instance visually to assist you understand the hint for the solution of "how numerous times a work a clock"s hands overlap?".

*

We have actually one base mathematical equation because that this trouble that will lead united state to solution.The minute hand is 12 times faster than the hour hand.If girlfriend think of the time passing indigenous 12:00 o"clock come 1 o"clock, the minute hand travel 360 degrees. Meanwhile the hour hand travel 1/12 of 360 degrees.Or in a various thinking, in a certain time duration (t) minutes, the minute hand travels (360 * t) / 60 degreesBut at the same time the hour hand only travels 1/12 of that degree: (360 * t) / (60 * 12) degrees.

An other equation originates from the pass hours. Each passing hour the minute hand completes a full cycle.Let"s say the the hour hand travel (n) degrees. So we have the right to say at when they overlap each various other the minute hand travel (360 + n) degrees at the same time as hour hand.

So we have the right to now say that while hour hand travels (n) levels the minute hand will travel (12*n) degrees.The result that will outcome native this added equation with an initial mathematical equation will certainly be together follows:

12 * n = 360 + n

Of food 360 degrees is true if just 1 hour has actually passed.If two hours passed, then the formula will certainly be: 12 * n = 360*2 + nSo we deserve to re-formulate the equation as follows:

12 * n = 360 * h + n

Now replace n the degree 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 can replace h with 1 and we can solve the equation for an initial 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 require to convert it come seconds.

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

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

Then us can continue calculation for the second overlap of clock"s hands. This will certainly occur in between 2 o"clock and also 3 o"clock.This means minute hand that the clock will travel 2 times complete circle and plus the very same amount as hour hand.

Now I desire to relocate all this calculations into below Javascript code

Javascript Code

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

There is a Javascript Loop structure to calculation each time the minute hand completes a full cycle.Since in a job the sample from midnight till noon will certainly be exact same for the second fifty percent of the work (from noon it rotates midnight), the Javascript loop is characterized for an creature variable beginning from 0 come 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 occurs at " + hour + ":" + minute + ":" + secs + "");}
Code

Within the loop, each overlap condition is calculated making use of the mathematical equation debated in ahead section.For loop structure consists of mod functions and also Mart.floor() attributes for converting the moment in minutes to hours:minutes:seconds display format.

See more: Answer To Sitting At A Four Legged Table, At A Four Legged Table Riddle Answer

As you watch in the output of this sample Javascript code, an initial overlap occurs at 00:00:00 o"clock.And the critical overlap that clock"s hand will happen at 24:00:00To prize the interview inquiry "How numerous times a work a clock"s hands overlap?", first of all we should identify if first overlap time that is the beginning time counts or not.I assume the we deserve to agree the start time is additionally one of the overlapping times in a day.So, here is the times count and also clock"s hands overlap time within 24 hours:1. Time overlap occurs at 00:00:002. Time overlap wake up at 01:05:273. Time overlap occurs at 02:10:544. Time overlap wake up at 03:16:215. Time overlap occurs at 04:21:496. Time overlap wake up 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 wake up at 10:54:3212. Time overlap wake up at 12:00:0013. Time overlap wake up at 13:05:2714. Time overlap occurs at 14:10:5415. Time overlap occurs at 15:16:2116. Time overlap wake up 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 beginning as among overlaps, this might be excluded)

As a result, if you count the last case, there room 23 times as soon as a clock"s hour and also minute hand overlap in a day.If friend exclude among the midnights, we deserve to conclude the there space 22 times once a clock"s hand overlap in a day.