LET'S TALK TECHNICAL

This blog is intended to help people prepare for the job interviews and improve their analytical skills. We have posted difficult datastructures and algorithm questions and puzzles. Interview experiences section is for the people to post their interview experiences.Views expressed here are of their personal and the blog author doesn't take any responsibility for the same.

-

Followers

Jobs

Wednesday, December 5, 2007

Four people crossing the bridge optimally

Four people need to cross a rickety rope bridge to get back to their camp at night. Unfortunately, they only have one flashlight and it only has enough light left for seventeen minutes. The bridge is too dangerous to cross without a flashlight, and it is only strong enough to support two people at any given time. Each of the campers walks at a different speed. One can cross the bridge in 1 minute, another in 2 minutes, the third in 5 minutes, and the slow poke takes 10 minutes to cross. How do the campers make it across in 17 minutes?

Sol:
When two people walk and their speeds are different then the time taken(cost) to cover some distance will be the time taken by slowest of the two.

first take 1, 2 to side2 cost = 2
get 2 back to side1 cost = 2
then take 5,10 to side2 cost = 10
get 1 back to side 1 cost = 1
get 1 and 2 back to side2 cost =2

total cost = 17

100 couples C cheats problem?

Every man in a village of 100 married couples has cheated on his wife. Every wife in the village instantly knows when a man other than her husband has cheated, but does not know when her own husband has. The village has a law that does not allow for adultery. Any wife who can prove that her husband is unfaithful must kill him that very day. The women of the village would never disobey this law. One day, the queen of the village visits and announces that at least one husband has been unfaithful. What happens?

Sol:
At the end of Cth day all of the cheats get killed if there are C cheats

Five Pirates gold coins division problem.

You have five pirates, ranked from A to E in descending order. The top pirate has the right to propose how 100 gold coins should be divided among them. But the others get to vote on his plan, and if fewer than half agree with him, he gets killed. How should he allocate the gold in order to maximize his share but live to enjoy it? (Assumption : If the top pirate is voted down and gets killed, then the remaining pirates retain their rankings and continue the game, with Pirate 4 now in charge etc.. 2) top pirate also have the voting right and he will not be killed if there is a tie in number of votes)

Ans: 98 coins with top pirate

This is a game theory problem which involves some reasoning.
Lets start to the solution as if there are only 2 pirates. In this case, the top-ranked pirate (Pirate B) would get 100 gold coins, and Pirate A wouldn't get any, because Pirate A has no way to vote down the plan.

Let's work backwards from there. Clearly, Pirate A doesn't want it to come down to just two people. So consider if there were three pirates. Then, Pirate A would accept even just one coin to avoid letting things get down to two people. Thus, if there were three pirates involved, Pirate C should offer Pirate A a single coin; Pirate A would agree because one coin is better than zero. Pirate B could not overrule this plan.

Lets say there are 4 pirates, Pirate B would accept even just one coin to avoid letting things get down to three pirates; if it got down to three, as we have shown above, Pirate B would get nothing. Thus, Pirate D could offer to keep 99 coins and pay Pirate B a single coin; Pirate A and Pirate C would get nothing, but they don't have enough votes to override the plan.

Coming to actual five pirates case , Pirate A and Pirate C are anxious to avoid letting things get down to four pirates, because then they'd get nothing. So if Pirate E offered Pirate A and Pirate C a single coin each, then they'd vote in favor of the plan, since one coin would be better than nothing.
So Pirate E keeps 98 coins for himself.


Generalized answer is
If there are odd number of pirates then
the number of coins with top pirate = total number of coins - number of odd numbers below the number.
else
the number of coins with top pirate = total number of coins - number of even numbers below the number.

Proff for above formulae can be established by following
In case of 6 pirates: Pirate F would have to offer a coin to Pirates B and D to satisfy everyone's self-interests.
In case of 7 pirates : Pirate G would have to offer a coin to Pirates A, C, and E.

audio resume,answers link?

Useful link with interview answers audios.
http://www.midemo.com/validator_online/rep/gads.php?HashCode=10ac8f04c270fbf0fc6bd1d975172f28&gclid=CLLTt-aikZACFQFeQgodLzEaAA

Popular Posts