we will start with both the hour-glasses and as soon as the sand flows to the other bulb we will invert it.this inversion process will be done three times for both the hourglss. we start measuring time after the third inversion of 4-min hourglass and measure it till the complete sand flow of 7-min hourglass.
Given an integer n, write a function that returns count of trailing zeroes in n!. Examples: Input: n = 5 Output: 1 Factorial of 5 is 20 which has one trailing 0. Input: n = 20 Output: 4 Factorial of 20 is 2432902008176640000 which has 4 trailing zeroes. Input: n = 100 Output: 24
we will start with both the hour-glasses and
ReplyDeleteas soon as the sand flows to the other bulb
we will invert it.this inversion process will be done three times for both the hourglss.
we start measuring time after the third inversion of 4-min hourglass and measure it till the complete sand flow of 7-min hourglass.
time= 7*3-4*3 = 9 minutes.
@navin good approach.you are using total of 6 inverts.you can improve it.
ReplyDeleteTime 4m timer 7 minute timer
ReplyDelete0 min Start Start
4 mins Flip 3 minutes left
7 mins 1 m left Flip
8 mins Stop Flip (1 minute left)
9 mins Stop
In this approach only 3 inverts are required.