Table of contents
1.
Introduction
2.
Puzzle Description
3.
Solution
4.
Frequently Asked Questions
4.1.
How should we solve the puzzles during the interview?
4.2.
How do we prepare the puzzles for the interview?
4.3.
Should we always reach the correct answer to the puzzle during the interview?
5.
Conclusion
Last Updated: Mar 27, 2024

Medicine Chest on a Boat

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
Interview Puzzles

Introduction

During your interview, you may encounter puzzles apart from technical questions. Puzzles are a good measure of one's analytical skills and lateral thinking. Many companies ask for puzzles in their interviews to filter the candidates based on their real-life problem-solving skills. You can get perplexed if you are not ready for them. 

The interviewer is generally interested in the candidate's approach while solving the puzzle. Solving different puzzles can help you build up the thinking skills and the out-of-the-box approach the companies demand.

Let us look at an exciting puzzle frequently asked in the interviews.

Puzzle Description

Alice and Bob are on separate islands. Bob is sick, and Alice has the medicine. Eve has a boat and a chest that can be locked. She is willing to transport objects between Alice and Bob, but only in the chest, and if the chest is unlocked, she will steal whatever is inside. If both Alice and Bob have a padlock and a key such that their own key only opens their own lock, is it possible for Alice to send the medicine to Bob so that Eve won't steal it? If yes, what are the minimum number of trips required?

Note: 

  1. Alice and Bob cannot travel on the boat. 
  2. The boat going from Alice to Bob or Bob to Alice is counted as one trip.

Solution

Let us try to understand the puzzle:

We know that Bob is stuck on an island and is sick and needs medicine. Alice has medicine, but she is on another island. The only mode of transportation of goods between those two can be done by Eve by a boat. The boat has a chest that can be locked by multiple locks. Eve will steal the chest if it is not locked. Bob and Alice have their own padlocks with their respective keys. Alice and Bob can close the chest by using one lock or both their locks. We have to determine whether Alice can send the medicine to Bob and the minimum number of trips if it is possible.

a chest that can be locked by multiple padlocks

A chest that can be locked by multiple padlocks

At the start of the trip, Alice has the medicine and her lock (let us call if lock A) while Bob has his lock (lock B).

Trip 1:

Alice puts the medicine in the chest and locks it with lock A and keeps its key with her. Eve transports the medicine locked in the chest to Bob. Bob cannot open the chest.

Trip 2:

Now Bob locks the chest with his lock B. The chest is locked by both locks. Eve transports the chest back to Alice.

Trip 3:

Alice opens lock A with her key, and now Eve transports the chest back to Bob. The chest is still locked by lock B.

Finally, Bob opens lock B with his key and retrieves the medicine.

Answer:  3 trips

This is the minimum number of trips needed to transport the medicine without being stolen.

Check out this problem - 8 Queens Problem

Frequently Asked Questions

How should we solve the puzzles during the interview?

Think about the problem and try to understand the question. Ask for clarifications if you feel that you do not understand the puzzle. Getting the right answer is not as important as your approach. Always explain your approach while answering.

How do we prepare the puzzles for the interview?

The best approach is to practice different puzzles and solve the previously asked puzzles.

Should we always reach the correct answer to the puzzle during the interview?

You should focus on your approach and your ability to convey it to the interviewer. Sometimes, you may not be able to reach the correct answer, but if your approach is right, it does not matter much.

Conclusion

This article solved a famous puzzle called the medicine chest on a boat puzzle. You can solve any puzzle asked in your interview if you keep practicing these types of puzzles. 

Recommended Readings:


Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Interview Puzzles, Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Live masterclass