Poor Pigs
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
There are buckets buckets of liquid, and **exactly one** is poisoned. You have pigs to find it and minutesToTest minutes in total.
A test round works like this: pick any set of live pigs, let each drink from any subset of buckets (instantly, drinking from many buckets at once is allowed), then wait minutesToDie minutes. Any pig that drank the poison dies at the end of the wait; the others survive and can be reused. You can run rounds back to back for as long as the total time allows (at most floor(minutesToTest / minutesToDie) rounds).
Return the **minimum number of pigs** needed to guarantee identifying the poisoned bucket within the time limit. With a single bucket no pigs are needed.
Examples
Constraints
- `1 <= buckets <= 1000`
- `1 <= minutesToDie <= minutesToTest <= 100`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.