Amazon Interview Question: Binary Solution to the Poison Bottle Problem Explained

Use binary encoding to solve the Poison Bottle Problem with just ⌈log₂(n)⌉ mice.
This article breaks down Amazon's classic Poison Bottle Problem, where you must identify one poisoned bottle among n bottles using the fewest mice. By treating each mouse's life or death as a binary bit, the solution leverages binary encoding to pinpoint the poison with just ⌈log₂(n)⌉ mice — a powerful demonstration of information theory applied to interview problems.
A Classic Amazon Interview Question
In algorithm interviews, some questions appear deceptively simple yet precisely test a candidate's abstract thinking and mathematical modeling skills. The "Poison Bottle Problem," which has appeared in Amazon interviews, is a prime example.
Here's the problem: You have n bottles, and exactly one of them contains poison. You can use mice to test — each mouse can drink from any number of bottles, but if any of the liquids it drinks contains poison, the mouse will die.
The question is: What is the minimum number of mice needed to identify the poisoned bottle?

The beauty of this problem is that it doesn't require complex data structures or advanced algorithms. Instead, it requires you to break free from the linear thinking pattern of "one mouse per bottle" and discover the essence of information encoding.
Start with the Simplest Case: 2 Bottles Need Only 1 Mouse
The classic approach to solving logic puzzles like this is to start reasoning from the smallest possible scenario.
Suppose we have only 2 bottles. We actually need just 1 mouse:
- Have the mouse drink from the first bottle;
- If the mouse dies, the first bottle is poisoned;
- If the mouse survives, the poison must be in the second bottle.

The key insight here is: a single mouse has two possible final states — alive or dead. These two states are exactly enough to distinguish between 2 bottles. In other words, one mouse carries "1 bit" of information.

Following this line of thinking, we naturally ask: if each mouse carries 1 bit of information, how many distinct outcomes can multiple mice express together?
Binary Encoding: The Core Solution to the Poison Bottle Problem
The answer lies in binary representation.
Each mouse has two states — "dead" and "alive" — which we can denote as 1 and 0 respectively. With k mice, the total number of state combinations is 2^k. Each combination uniquely corresponds to a bottle's number.
Therefore, to distinguish among n bottles, we need:
2^k ≥ n
Solving for k:
k = ⌈log₂(n)⌉
In other words, the minimum number of mice required equals the ceiling of the base-2 logarithm of n.
Step-by-Step Binary Encoding Procedure
In practice, here's how to set it up:
- Assign each bottle a number starting from 0, and write it in binary form;
- The i-th mouse drinks from all bottles whose i-th binary digit is 1;
- After the test, observe which mice have died;
- Set the binary digits corresponding to dead mice to 1 and surviving mice to 0 — the resulting binary number is the poisoned bottle's number.
For example, if the mice at positions 0 and 3 die while the rest survive, the poisoned bottle's number is 1001 in binary, which is 9 in decimal.
Practical Verification: How Many Mice for 1,025 Bottles?
The video provides an excellent example: if there are 1,025 bottles, how many mice are needed?
Let's calculate:
- 2^10 = 1,024, which isn't enough to cover 1,025 bottles;
- 2^11 = 2,048, which is sufficient.
So the answer is 11 mice.

This result confirms the formula ⌈log₂(1025)⌉ = 11. Just 11 mice can pinpoint the single poisoned bottle among 1,025 — the information compression efficiency of binary encoding is truly remarkable.
Why This Question Is a Favorite at Top Tech Companies
There are three reasons why this problem frequently appears in interviews at companies like Amazon:
First, it tests abstract modeling ability. Candidates must recognize that "a mouse's life or death" is equivalent to "a binary bit" — this abstraction is the make-or-break moment in solving the problem.
Second, it embodies information theory principles. Each test gathers information, and log₂(n) represents the minimum amount of information needed to distinguish among n objects. Understanding this is key to seeing why the answer isn't n or n/2, but logarithmic.
Third, it's highly extensible. This problem has more complex variants, such as "multiple rounds of testing allowed" or "multiple poisoned bottles," all of which build upon this foundation. Mastering the encoding approach of the basic version is a prerequisite for tackling these variants.
Summary: Master Binary Encoding Thinking for Interviews
The Poison Bottle Problem is a classic "less is more" interview question: it doesn't rely on coding tricks but tests whether you can re-examine a problem through the lens of binary encoding.
The core conclusion fits in a single sentence — to distinguish among n bottles, you need at minimum ⌈log₂(n)⌉ mice.
If you're preparing for algorithm interviews, consider this problem excellent training material for abstract thinking. The next time you encounter a question about "distinguishing the maximum number of states with the fewest resources," remember to ask yourself: Can the information here be encoded in binary?
Related articles

Resume Guide for Programmers Transitioning to AI: From an HR Perspective to Job Requirement Matching
How should programmers transitioning to AI write a resume? This Bilibili tutorial gives five key preparation actions: set aside two or three days to review skills and projects, choose a simple template, reverse-engineer the tech stack from job sites, emphasize LLM capabilities, and do a final check from an HR perspective.

Building a RAG Knowledge Base: A Complete Guide from Architecture to Retrieval Evaluation
A systematic overview of the full RAG knowledge base workflow: from overall architecture and mature retrieval solutions to key details of retrieval evaluation and who should learn it, helping developers build a path from beginner to hands-on practice.

Turn Screenshots into Web Code in Seconds: Anyone Can Write HTML with AI
A Bilibili creator demonstrates using AI to turn webpage screenshots directly into HTML and CSS code without manual coding. The article analyzes the tool's usage, new features like video-based app cloning, iterative refinement, and the real boundaries of AI giving zero-foundation users programming ability.