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.
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
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