Poison and Rat — Puzzle for Interview rounds

Question :

There are 1000 wine bottles. One of the bottles contains poisoned wine. A rat dies after one hour of drinking the poisoned wine. How many minimum rats are needed to figure out which bottle contains poison in hour.

Solution :

We need to figure out in hour. We need 10 rats to figure out the poisoned bottle. The result is based on binary number system. We get 10 using ⌈Log(base 2)1000⌉.

The idea is to number bottles from 1 to 1000 and write their corresponding binary numbers on the bottle. Each rat is assigned a position in the binary numbers written on bottles. Let us take an example. Rat 1 represents first bit in every bottle, rat 2 represents second bit and so on. If rat numbers 5, 7 and 9 die, then bottle number 42 (Binary 0000101010) is poisoned.

Thanks for Reading

Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.

Learn more at Placewit. Follow us on Instagram and Facebook for daily learning.

--

--

--

Upskilling students for tech placements!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Microcontroller: Technology which never rusted, Never Will

10 Lessons Learned Extracting a Service from a Monolith

The SWIM Membership Protocol

SWIM Failure Detector

Import Yelp data into your local DynamoDB

Obtaining the value of x raised to the power of y by recursion in C Language.

Road — TryHackMe

Flutter Method Channels on Linux

Good Code Matters

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Placewit

Placewit

Upskilling students for tech placements!

More from Medium

Jelly Beans Jars Puzzle

Google / Microsoft Interview Question — LeetCode 833

Knight Probability in Chessboard Solution | LeetCode-688: Medium | JavaScript Implementation

Cognizant Interview Experience