2008年1月21日星期一

Microsoft Interview Questions 2

Question:
FIND A JAR WITH A CONTAMINATED PILL FROM A SET OF JARS

You have 4 jars of pills. Each pill is a certain weight, except for contaminated pills contained in one jar, where each pill is weight + 1. How could you tell which jar had the contaminated pills in just one measurement?

Answer
Take 1 pill from jar 1, 2 pills from jar 2, 3 pills from jar 3, and 4 pills from jar 4, then weigh all 10 pills together. The total weight will be 10*weight + k, where k = # of contaminated pills that were measured. Thus, if k=1, the contaminated jar is jar 1, or if k=2, the contaminated jar is jar 2, etc.

Another interesting side point. You only need to take pills out of 3 jars (1 from jar1, 2 from jar2, and 3 from jar3). If the weight = 6*weight, then the contaminated jar is jar 1, otherwise proceed as usual. This is how you can determine the contaminated jar in one weighing with the minimal number of pills involved (assuming you can't break up a pill).


Question:

There are 4 women who want to cross a bridge.
They all begin on the same side. You have 17 minutes to get all of them across to the other side. It is night. There is one flashlight. A maximum of two people can cross at one time. Any party who crosses, either 1 or 2 people, must have the flashlight with them. The flashlight must be walked back and forth, it cannot be thrown, etc. Each woman walks at a different speed. A pair must walk together at the rate of the slower woman's pace.
Woman 1: 1 minute to cross
Woman 2: 2 minutes to cross
Woman 3: 5 minutes to cross
Woman 4: 10 minutes to cross
For example if Woman 1 and Woman 4 walk across first, 10 minutes have elapsed when they get to the other side of the bridge. If Woman 4 then returns with the flashlight, a total of 20 minutes have passed and you have failed the mission. What is the order required to get all women across in 17 minutes? Now, what's the other way?

Answer:
1 and 2 go and 1 comes back. Total Time= 3 mins


Question:

IF YOU HAD AN INFINITE SUPPLY OF WATER AND A 5 QUART AND 3 QUART PAIL, HOW WOULD YOU MEASURE EXACTLY
If you had an infinite supply of water and a 5 quart and 3 quart pail, how would you measure exactly 4 quarts?

Answer:
Step 1: Fill the 5 Qaurt first and then empty it in the 3 Quart. So in the 5 Quart is filled with 2 Quart of water and the 3 Quart is fuly filled.

Step 2: Empty the 3 Quart

Step 3: Empty the water (2 Quarts) that is filled in the 5 Quart into the 3 Quart. So the 5 Quart is empty and the 3 Quart is filled with 2 Quarts of water.

Step 4: Now fill the 5 Quart fully with water and pour it in the 3 Quart till the 3 Quart becomes fully filled. Now the 5 Quart is filled with exactly 4 Quarts of water.


then 3 and 4 go and 2 comes back. Total Time in this = 12 mins

lastly 1 and 2 go. Total Time: 2 mins

Net total time to cross= 3+12+2= 17 mins

沒有留言: