Skip to content

Practice Poor Pigs

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#458
LeetCode Problem

Poor Pigs

Problem Statement

The number of liquid buckets is given by buckets. Exactly one is poisonous. You have minutesToTest minutes to identify it. In each testing round, choose live pigs and assign any number of buckets to each one; a bucket may be assigned to multiple pigs. Feeding takes no time, and each pig drinks all its assigned samples simultaneously. Then wait minutesToDie minutes without feeding any other pigs. Pigs given poison die at the end of that wait; the others survive and may participate in another round. Return the fewest pigs that guarantee identifying the poisonous bucket within the time limit.

Source: Poor Pigs on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
buckets = 4, minutesToDie = 15, minutesToTest = 15
Output
2

# Example 2

Input
buckets = 4, minutesToDie = 15, minutesToTest = 30
Output
2

Constraints

1 <= buckets <= 1000
1 <= minutesToDie <= minutesToTest <= 100

Related LeetCode Problems

Practice more problems similar to Poor Pigs.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.