There is a desert of 1000kms long. A camel is there and 3000 bananas. At one go a camel can take 1000 bananas. For each one km to walk camel eats 1 banana. How many bananas can we cross to the other side of desert.
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.
500 bananas
ReplyDeleteby stopping at each 1/4th distance i.e. 250 km till it reaches 500 km and then directly sopping at the end.
good navin..
ReplyDeleteI think there is a more optimal solution.....seems like author needs to crosscheck the same !!!
ReplyDeleteyes optimal solution will be 533 more precisely(533.33).
ReplyDeletewhen u have B(banana count) > 2000 & <= 3000; to take the lot 1 Km u need 5 bananas, so when u have traveled 200 Km, B=2000.
Now to take this lot 1 km u need 3 bananas,so when u have traveled 333.33 Km, B=1000.
Now to take this lot u need only 1 banana per kilometer , therefore to travel remaining distance (1000 - 200 -333.33) u need 466.67 bananas
so bananas left is (B - 466.67) = 533.33