Using Javascript, as a software program developer I"ll try to prize interview question "How many times a work a clock"s hands overlap?" through the precise overlapping time of the clock"s hour hand and also minute hand.This tricky inquiry was request by mine manager to one of our intern college student.Later we learnt the this inquiry "How countless times do a clock"s hand overlap in a day?" is an interview inquiry asked for job applicants in Google.

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


Let"s first analyze the problem of overlapping clock"s hour and also minute hands.First set our imagine clock come 12:00 midnight which is the beginning time for the troubles time period.

*

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

Now assume the the clock"s hour and also minute hands overlap because that the next time.The an initial overlapping ~ 12:00 o"clock will certainly happen in between 1 o"clock and also 2 o"clock.But we do not understand the exact time right currently at this stage of the trouble solution.

*

Let"s examine the over situtation now. An initial of all, clock"s hour hand only moved from position 12 to a position in between 1 and also 2. What is amazing for the equipment of this inteview question is the at the same time period, the minute hand that the clock perfect a full cycle starting from 12 to 12 and in addition traveled the same distance as hour hand in ~ the overlapping time.

Here is a illustration displaying the case visually to assist you recognize the hint for the equipment of "how plenty of times a work a clock"s hands overlap?".

*

We have one base mathematical equation for this trouble that will certainly lead us to solution.The minute hand is 12 times much faster than the hour hand.If you think of the moment passing from 12:00 o"clock come 1 o"clock, the minute hand travel 360 degrees. On the other hand the hour hand travels 1/12 the 360 degrees.Or in a various thinking, in a specific time period (t) minutes, the minute hand travel (360 * t) / 60 degreesBut at the exact same time the hour hand just travels 1/12 of the degree: (360 * t) / (60 * 12) degrees.

An various other equation comes from the passed hours. Every passing hour the minute hand completes a full cycle.Let"s say that the hour hand traveled (n) degrees. Therefore we deserve to say at when they overlap each other the minute hand travel (360 + n) degrees at the same time together hour hand.

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

12 * n = 360 + n

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

12 * n = 360 * h + n

Now replace n the degree the hour hand traveled with 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 have the right to replace h v 1 and we have the right to solve the equation for an initial overlap after ~ 12:00 o"clock

t = 720 /11 = 65,45 minutes

There is an various other tricky conversion here the decimal component of the time. We need to transform it to seconds.

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

So the very first overlap is at 65 minute 27 seconds later on which way 1:05:27

Then us can continue calculation because that the 2nd overlap of clock"s hands. This will certainly occur in between 2 o"clock and 3 o"clock.This method minute hand the the clock will travel 2 times full circle and plus the same amount as hour hand.

Now I desire to relocate 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 hands overlap in a dayPlease keep in mind that the below Javascript code is detailed by Hilal �etinkaya, ours intern student. Many thanks a lot for her assist for the systems of this amazing 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 half of the day (from noon it rotates midnight), the Javascript loop is defined for an creature variable beginning 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, every overlap condition is calculated making use of the math equation questioned in previous section.For loop structure has mod functions and also Mart.floor() functions for converting the moment in minutes to hours:minutes:seconds display screen format.

See more: What Test Can Be Performed To Detect A Leak After Fueling A Gasoline-Powered Boat

As you view in the calculation of this sample Javascript code, very first 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 concern "How numerous times a job a clock"s hands overlap?", very first of all we should determine if first overlap time the is the starting time counts or not.I assume that we have the right to agree the start time is likewise one that the overlapping times in a day.So, below is the time count and also clock"s hands overlap times within 24 hours:1. Time overlap occurs at 00:00:002. Time overlap occurs 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 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 occurs 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 occurs 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 wake up at 19:38:1020. Time overlap wake up at 20:43:3821. Time overlap wake up 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 can be excluded)

As a result, if you count the critical case, there room 23 times as soon as a clock"s hour and minute hand overlap in a day.If you exclude one of the midnights, we deserve to conclude that there room 22 times once a clock"s hand overlap in a day.