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.

Implement a function getbits, that returns the(right adjusted) n bits that begin at position p of an integer. Assume bit position 0 is at the right end and that n and p are sensible positive values.

You are given n real numbers in an array. A number in the array is called a decimal dominant if it occurs more than n/10 times in the array. Give an O(n) time algorithm to determine if the given array has a decimal dominant.

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.