Interview Question


Country: United States




Comment hidden because of low score. Click to expand.
1
of 1 vote

This problem should be solved using binary representation.

Lest assume the poison takes 2 hours to affect, the solution of 1 rat is not feasible as we will have to wait to lot of time to determine which bottle is poisoned. The simple solution is by using binary representation lets assume bottle 3rd is poisoned.

Step 1) represent all the bottles using binary representations.

Bottle 1 : 0001
Bottle 2 : 0010
Bottle 3 : 0011 (Poisoned)
Bottle 4 : 0100


Step 2) Arrange all the rats in a line.
Step 3) according to the bottles binary representation git a drop of wine to the rats for digit 1.
Rat1 Rat2 Rat3 Rat4
- - - -
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0

Now according to our assumption all the rats which were given a drop from bottle 3 Should die. which would be rat 3 and rat 4.
Assume the red rats to be 1's and alive rats to be 0's which comes out to (0011) which is exactly the number of our bottle.

This approach kills 2 Rats. There's no where mentioned that we should try to keep as many rats alive possible.

- Sameer October 30, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

2 rats

- itscareerprince October 30, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1, check one by one

- m250892 October 30, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Depends on how long the poison takes to act and how long you have to perform the test. Worst case, four rats, best case one rat.

If time is at least 3x the acting time of the poison, one rat.
If time is less than 2x the acting time of the poison, four rats.
Between 2x and 3x, two rats.

Latency matters.

- Michael Gat October 30, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1, if its milk then continue ,if poison stop.

- Anonymous November 01, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

lets assume
1 rats are to be fed once and at the same time and we know how fast the poison acts, then the following would be optimal
feed rat1 with milk1 and milk2
feed rat2 with milk2 and milk3
wait for the time the poison should act
if only rat1 dies milk1 has poison
if both rat1 and rat2 die then milk2 has poison
if only rat2 dies then milk3 has poison
if no rats die then milk4 has poison

- PeyarTheriyaa November 01, 2018 | Flag Reply


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