Problem There are n bikes and each can cover 100 km when fully fueled. What is the maximum amount of distance you can go using n bikes? You may assume that all bikes are similar and a bike takes 1 litre to cover 1 km.
Solution There are couple of ways. Lets find the right solution. Say n = 50.
Naive Solution:
The most naive solution would be to just make all the bikes go together.
[Read More]
Maximum number of chickens you cannot order
Problem There is a non vegetarian restaurant which sells chicken in orders of 6, 9 and 20.
Calculate the maximum number of chicken pieces you cannot order from that restaurant ?
Solution 43
If you analyze, then you will find that all the 6 numbers divisible by 3 can be ordered. Why? Because you can break them own as the sum of 6 and 9.
Now after 26, all the numbers that are divisible by 3 if subtracted by 40 can be obtained.
[Read More]
int atoi( char* pStr )
Problem: Write the definition for this function without using any built-in functions. if pStr is null, return 0. if pStr contains non-numeric characters, either return 0 (ok) or return the number derived so far (better) (e.g. if its “123A”, then return 123). assume all numbers are positive. plus or minus signs can be considered non-numeric characters. in order to solve this program, the programmer must understand the difference between the integer 0 and the character ‘0’, and how converting ‘0’ to an int, will not result in 0.
[Read More]
Reverse a String
Problem: A typical programming interview question is “reverse a string, in place”. if you understand pointers, the solution is simple. even if you don’t, it can be accomplished using array indices. i usually ask candidates this question first, so they get the algorithm in their head. then i play dirty by asking them to reverse the string word by word, in place. for example if our string is “the house is blue”, the return value would be “blue is house the”.
[Read More]
The Circular Lake Monster Problem
Problem: For #1, how about row in a circle a bit smaller 1/4r in size. Since he won’t be able to keep up with you, when he is on the opposite shore you can make a brake for it. You have r*3/4 to travel, but 4*3/4 is less then pi, so he won’t be able to catch you in time
Solution: Assume x is the monster’s speed. Then to get the circle trick to work, you row a circle a little less than 1/x of the radius, leaving you 1 - 1/x to row when he is opposite of you.
[Read More]
Array of 0 and 1, put 0's at even position and 1's at odd position
you are given an array of integers containing only 0s and 1s. you have to place all the 0s in even position and 1s in odd position and if suppose no if 0s exceed no. of 1s or vice verse then keep them untouched. Do that in ONE PASS and WITHOUT taking EXTRA MEMORY.
input array:
{0 1 1 0 1 0 1 0 1 1 1 0 0 1 0 1 1 }
[Read More]
Chain Cut Problem
Problem: What is the least number of links you can cut in a chain of 21 links to be able to give someone all possible number of links up to 21
Solution: Assume that a chain of length k for every 1<=k<=length(chain) must be doable with the open links. Then you can reach **links length dissection** 0 1 1 1 5 1-(1)-3 2 13 1-(1)-3-(1)-7 3 29 1-(1)-3-(1)-7-(1)-15 4 61 1-(1)-3-(1)-7-(1)-15-(1)-31 n 2^(n+2)-3 we have taken links as 2^k-1.
[Read More]
jelly beans
Problem:
you have three jars that are all mislabeled. one contains peanut butter jelly beans, another grape jelly jelly beans, and the third has a mix of both (not necessarily a 50/50 mix, could be a 1/99 mix or a 399/22 mix). how many jelly beans would you have to pull out, and out of which jars, to find out how to fix the labels on the jars?
| | | | | | |jar 1| |jar 2| |jar 3|
[Read More]
Pirates
Problems
five pirates have 100 gold coins. they have to divide up the loot. in order of seniority (suppose pirate 5 is most senior, pirate 1 is least senior), the most senior pirate proposes a distribution of the loot. they vote and if at least 50% accept the proposal, the loot is divided as proposed. otherwise the most senior pirate is executed, and they start over again with the next senior pirate.
[Read More]
sum it up
<br /> <!--<br /> /\* Font Definitions \*/<br /> @font-face<br /> {font-family:"Cambria Math";<br /> panose-1:2 4 5 3 5 4 6 3 2 4;<br /> mso-font-charset:1;<br /> mso-generic-font-family:roman;<br /> mso-font-format:other;<br /> mso-font-pitch:variable;<br /> mso-font-signature:0 0 0 0 0 0;}<br /> @font-face<br /> {font-family:"Arial Unicode MS";<br /> panose-1:2 11 6 4 2 2 2 2 2 4;<br /> mso-font-charset:128;<br /> mso-generic-font-family:swiss;<br /> mso-font-pitch:variable;<br /> mso-font-signature:-134238209 -371195905 63 0 4129279 0;}<br /> @font-face<br /> {font-family:"\\@Arial Unicode MS";<br /> panose-1:2 11 6 4 2 2 2 2 2 4;<br /> mso-font-charset:128;<br /> mso-generic-font-family:swiss;<br /> mso-font-pitch:variable;<br /> mso-font-signature:-134238209 -371195905 63 0 4129279 0;}<br /> /\* Style Definitions \*/<br /> p.
[Read More]