You have two ropes,each of them takes 1 hour to burn.But either rope has varying density so there is no consistency in time that it takes to burn for different section.How do you use these two ropes to calculate 45 minutes.
Take two ropes. Put them side by side parallal Light top of first rope and down of another rope When the flames meet that means 30 minutes elapsed At the instant when they meet light the bottom of the first rope or top of another rope. When it finishes 15 minutes elapsed. So(30+15)=45 minutes.
burn rope1 from both sides and rope 2 from 1 side. after 30 mins rope 1 will burn completely. now burn the other end of rope 2 it will burn in another 15 mins.
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.
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.
Take two ropes.
ReplyDeletePut them side by side parallal
Light top of first rope and down of another rope
When the flames meet that means 30 minutes elapsed
At the instant when they meet light the bottom of the first rope or top of another rope.
When it finishes 15 minutes elapsed.
So(30+15)=45 minutes.
As mentioned the ropes have varying density so it can not be guaranteed that when 30 minutes is elapsed they both will meet at some point.
ReplyDeleteburn rope1 from both sides and rope 2 from 1 side.
ReplyDeleteafter 30 mins rope 1 will burn completely.
now burn the other end of rope 2 it will burn in another 15 mins.
This comment has been removed by the author.
ReplyDeletefold 1st rope from the middle and burn both the ends...once it gets burnt, burn the other rope from both ends.
ReplyDeleteyeah both approaches are correct...
ReplyDelete