1064. Poison Tasters
A palace kitchen has buckets identical pots of syrup, and exactly one of them has been poisoned. A taster who sips poison dies exactly minutesToDie minutes later and shows no sign before that. You have minutesToTest minutes in total. In a round, every taster may sip from any number of pots (sips may be mixed freely), then everyone waits minutesToDie minutes, after which the dead are known and a new round may start. Tasters who survived a round can be used again; the final results must be read when time is up.
Return the minimum number of tasters needed to guarantee finding the poisoned pot. Solve it in O(log(buckets)) time and O(1) space.
Example 1
- Input:
- buckets = 100, minutesToDie = 10, minutesToTest = 40
- Output:
- 3
- Explanation:
There are 4 rounds, so each taster ends in one of 5 states; 5^2 = 25 is too few for 100 pots but 5^3 = 125 is enough, so 3 tasters.
Example 2
- Input:
- buckets = 30, minutesToDie = 12, minutesToTest = 24
- Output:
- 4
- Explanation:
Only 2 rounds fit, so each taster has 3 possible outcomes; 3^3 = 27 falls short of 30 but 3^4 = 81 covers it, giving 4 tasters.
Constraints
1 ≤ buckets ≤ 109
1 ≤ minutesToDie ≤ minutesToTest ≤ 109
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(log buckets)
- Space
- O(1)