Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
4
of 6 vote

I guess I understand what hary said.
1. Number the 7 buckets as 1, 2, 3... 7.
2. Write each number in binary, 001, 010, ..., 111
3. Need 3 additional buckets, each corresponds to one bit in step2.
4. For each of the 7 buckets, put its water in the each of the 3 additional buckets if its corresponding bit is 1.
5. Put one fly to each of the 3 additional bucket
6. After 1 week, for each bucket, write down '1' if its fly is dead, write down '0' ow. Together, you know which one in the 7 buckets is positioned.

- Anonymous March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

perfect !!

- Unknown June 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

like

- jiangok2006 August 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

mix water from 6 buckets and leave one bucket alone. put 1 fly in any one of the mixed 6 buckets. If it it dies then send the 7th bucket else send any of the first 6 buckets.

- Anonymous March 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

good one !!!

- lick July 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

i think this is the correct (best) solution

- lick July 18, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

can anybody pls explain the question itself i cant even understand the question leave aside the solution

- piyush March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

try this way:
Day 1: fly in bucket 1
Day 2: take the fly from bucket 1 to bucket 2
Day 3: take the fly from bucket 2 to bucket 3
...
Day 7: keep the fly there
if the fly die, then we know bucket 1 is poisoned, we can give any other buckets to your friend. Otherwise, send the bucket 1, since it is non-poisoned. Then you wait for the Day 8 to see if fly dies, then you will see the bucket 2 ... and on and on....

- Anonymous June 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If the poisoned bucket was bucket 1 then you contaminated all the water buckets with the poisoned fly and just killed your friend.

- Sean December 08, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess I understand what hary said.
1. Number the 7 buckets as 1, 2, 3... 7.
2. Write each number in binary, 001, 010, ..., 111
3. Need 3 additional buckets, each corresponds to one bit in step2.
4. For each of the 7 buckets, put its water in the each of the 3 additional buckets if its corresponding bit is 1.
5. Put one fly to each of the 3 additional bucket
6. After 1 week, for each bucket, write down '1' if its fly is dead, write down '0' ow. Together, you know which one in the 7 buckets is positioned.

- twinba March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hey very good explnantion!

- Anono March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

This solution is too good. Hats Off!

- JamesBond March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The solution is amazing

- mcolinc March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

You don't need extra buckets.

Label each bucket 001 to 111 in binary.
Assign each of three flies a bit position (0, 1, 2).
Dip each fly in every bucket where his bit is set (e.g. fly-0 goes in every odd bucket).
Using dead flies as 1 and live flies as 0, write a binary number.
That's the poisoned bucket.

- J March 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

how many flies does ur approach take?
We need to reduce flies! twinba's soln. is the best!

- JamesBond March 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

J's solutions is simply brilliant..

- PT March 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@J or @PT .. i din understand the solution .. could u plz elaborate!

- TS December 08, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

J's solution is the right one. You do not need extra buckets. His approach uses 3 flies.

fly 1 - bit position 0
fly 2 - bit position 1
fly 3 - bit position 2

You have a fly for each position.

Buckets are numbered from 1-7, or 001-111.

Bucket 1 - dip fly 1 (bit position 0 set)
Bucket 2 - dip fly 2 (bit position 1 set)
Bucket 3 - dip flies 1 and 2 (bit positions 0 and 1 set)
...and so on

At the end of 7 days, check all three flies.

Only one will be dead, set that fly's bit position as 1.

The binary number formed gives the bucket number.

the key in this problem is that a fly does not have to remain in a poisoned bucket for 7 days to die. You only have to dip it once for it to die.

- Kk May 15, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

i tiwnba. can u please explain the question too then only i can understand the sol :)

- Anonymous March 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@all BTW IF WE JUST NEED TO SEND "ONE" BUCKET TO A FRIEND..AND JUST "ONE" IS POISONED WHY TO CARE FOR THE POISONED BUCKET??

jUST PUT IN ANY ONE BUCKET....IF THE FLY DIES SEND ANY OF THE OTHER TO THE FRIEND ELSE SEND THAT ONE... :)

- utscool March 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is really a nice Brain Teasers's solution!

- Yokuki March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

AWESOME!!!!
way to go dude!!!

- clrs March 12, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

it depends.
if the original question does not allow you to send a polluted (by a fly) bucket to your friend, then you cannot use this approach.

- Anonymous March 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think the question is wrong! Perhaps they would have said only one of them is non-poisonous and rest of them are poisoned. In such case, this 3 bucket solution works fine.

If they Q is only one poisonous bucket, then we can solve this with one additional bucket. This is to avoid sending a polluted bucket to fried :)

Take one additional bucket, and keep a drop of water from any of 7 buckets. Keep a fly in this new bucket and if the fly dies in 7 days - send any of the 6 other buckets. If the fly doesn't die, send the bucket from which the water drop is taken from.

- MK March 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

That would allow you to send your buddy a clean bucket, but the problem was to find the poisoned one AND send your buddy a clean bucket.

- J March 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes, J. By utscool's solution you can find a clean bucket in the first week and then send it out. And then in the following weeks to figure out which bucket is poisoned using the same fly.
I still think this one is the best answer cause it satisfy the requirement the most: find the poisoned one in 7 days and use least # of fly. ; )

- Yokuki March 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry, the last sentence should be:
I still think this one is the best answer cause it satisfy the requirement the most: find a clean one in 7 days and use least # of fly. ; )

- Yokuki March 14, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

can anybody explain the question please (:

- destiny March 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Put water in buckets 1 to 4 as:
Bucket1 = {1234}; Bucket2 = {2345}, Bucket3 = {3456} and Bucket4 = {4567}
Put 1 fly in these 4 buckets.
Depending on the fly dying on which bucket(s), we can easily determine which of the 7 buckets was originally poisoned.
Answer : 4 flies.

- Mukesh March 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its same as "The Emperor " Problem
+folj.
+com
+ /puzzles/very-difficult-analytical-puzzles
+.htm

1 The Emperor

You are the ruler of a medieval empire and you are about to have a celebration tomorrow. The celebration is the most important party you have ever hosted. You've got 1000 bottles of wine you were planning to open for the celebration, but you find out that one of them is poisoned.

The poison exhibits no symptoms until death. Death occurs within ten to twenty hours after consuming even the minutest amount of poison.

You have over a thousand slaves at your disposal and just under 24 hours to determine which single bottle is poisoned.

You have a handful of prisoners about to be executed, and it would mar your celebration to have anyone else killed.

What is the smallest number of prisoners you must have to drink from the bottles to be absolutely sure to find the poisoned bottle within 24 hours?

- ankushbindlish May 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its same as "The Emperor " Problem
+folj.
+com
+ /puzzles/very-difficult-analytical-puzzles
+.htm

1 The Emperor

You are the ruler of a medieval empire and you are about to have a celebration tomorrow. The celebration is the most important party you have ever hosted. You've got 1000 bottles of wine you were planning to open for the celebration, but you find out that one of them is poisoned.

The poison exhibits no symptoms until death. Death occurs within ten to twenty hours after consuming even the minutest amount of poison.

You have over a thousand slaves at your disposal and just under 24 hours to determine which single bottle is poisoned.

You have a handful of prisoners about to be executed, and it would mar your celebration to have anyone else killed.

What is the smallest number of prisoners you must have to drink from the bottles to be absolutely sure to find the poisoned bottle within 24 hours?

- ankushbindlish May 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

3!

- nagabhushana.s July 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If the goal is simply to send a non-poisoned bucked of water, then you can solve this with just 2 flies. How? Just separate the 7 buckets on 2 groups: one has 6 buckets and another just 1 bucket (presumably if you mix poisoned water with fresh water then all the water will be poisoned). You can select the buckets for each group randomly.
Then just mix the water from the 6 buckets and use a fly for each group (1 fly for the 6 bucket water and 1 fly for the solo bucket). Only one of the flies will die so you can send the water from the other group to your friend.

- Jose July 02, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 fly.
Dump out one bucket. Pour 1/3 from 3 different buckets into your empty bucket. Put the fly in there.
If the fly dies, you know the three full buckets are good.
If the fly lives, you know your three 2/3-full buckets are good. Split one of the buckets between the other two. Now you have two full buckets - one for you and one for your friend.

- Anonymous May 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

First, i dont know how one can make the fly die before seven days so - min days would still be 7
but yes "hw will u find out the poisoned bucket in least no of flies? " i guess the general solution is well known to everyone. (3 would be the no of flies used in normal case)

Correct me if i am missing something

- hary March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can u describe the algorithm?

- Tom March 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

hint: no your buckets using bits (one would require 3 bits in this case) and also the flies (a bit position set per fly)

- hary March 11, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Sorry, but still not clear with the solution. Can you please explain.

- Anonymous March 11, 2010 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More