Poor Pigs || Leetcode Hard 458 || Mathematical Solution

Опубликовано: 24 Март 2026
на канале: Digital Interview
1,876
22

There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous.

You can feed the pigs according to these steps:

Choose some live pigs to feed.
For each pig, choose which buckets to feed it. The pig will consume all the chosen buckets simultaneously and will take no time.
Wait for minutesToDie minutes. You may not feed any other pigs during this time.
After minutesToDie minutes have passed, any pigs that have been fed the poisonous bucket will die, and all others will survive.
Repeat this process until you run out of time.
Given buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time.



Example 1:

Input: buckets = 1000, minutesToDie = 15, minutesToTest = 60
Output: 5


Get notified about all off campus jobs/interviews and the process.
We are building our website and it will be back soon with lots of content till then subscribe us on youtube.
https://t.me/tech_geek1

Interview Preparation Sheet:    • INTERVIEW PREPARATION SHEET - HASHEDIN and...  

Link for Leetcode solutions:    • Leetcode Solutions  

Link for placement series:
Placement 2022:    • Placements 2022  
Placement 2023:    • Placements 2023  

#leetcode #leetcodesolution