Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024

Two Pills Each Day

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM
Interview Puzzles

Introduction 

Puzzles are good exercise for the brain. They help in enhancing the cognitive abilities of the brain helping with Problem Solving and related skills. There are numerous types of puzzles; each one having a logic inherent to itself which helps in cracking it. A good puzzle well is actually like a good mystery that we may have read about or watched on TV. It has the finest of hints which help in reaching its solution.

The following article discusses one such puzzle so let's get right to it.

Puzzle Description

You are on a strict scientific routine that calls for you to take capsules every day. You have to take precisely one A tablet and one B tablet simultaneously. The pills are costly, and also you don't need to waste any. So you open the bottle of A capsules and faucet one out into your hand. Then you open the bottle of B capsules and do the equal thing – however you're making a mistake, and B capsules pop out into your hand with the A tablet. But the capsules are all precisely identical. There isn't any manner to inform A pills other than B capsules. Is it feasible to fulfill your routine and take exactly one of every tablet at an equal time without losing any capsules?

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Solution

The first step can be to divide the three pills into identical halves or to split them in the middle. Then all three would have a left part and right part, after which you can place three left parts as a pile and three right parts as a separate pile. Now, every one of the two piles consists of 1/2 of tablet A and two halves of tablet B (or one tablet B). Now, take out one tablet A more from the bottle and reduce/ divide it into 1/2 or left and right parts. Put the two halves in a pile, the left one on the left stack and the right on the right bundle.

In this way, every pile now consists of 2 halves of tablet A and two halves of tablet B or one tablet A and one tablet B. You can now take one bank someday and the second one pile on the following day.

Explanation by Example

  • Let us say we have 10 A pills and 10 B pills.
  • According to the puzzle, you have one A pill and two B pills in hand, and both look identical. So here remaining pills of A are nine and of B is 8.
  • Now, take out one more pill of A. You have four pills in your hands that are identical, so the catch here is all four are similar, and you have to eat one from each of them without wasting it.
  • You have to partition them into two halve. Yes, you are getting it right. That is the left half and right half.
  • You must be wondering. They are identical. This makes no sense. Stick to this explanation, and you will find out the logic.
  • Finally, you have four left parts and four right parts. Here we can surely say that among the four left parts, two belong to the A pill category and the other two belongs to the B pill category.
  • The same is the case with the right half.
  • You have to eat the left half on one day and the right half on another day.
  • Because two left halves make a full tablet.

Check out this problem - 8 Queens Problem

Frequently Asked Questions

How to approach a puzzle interview problem?

  1. Thinking about problem
  2. Clarity regarding problem
  3. Use brute force first
  4. Try to make logic
  5. Get the solution

Why are puzzles asked in interviews?

To see how you will approach a real-time and tricky situation. 

What do you mean by puzzle reasoning?

It simply means analyzing the data given in the puzzle and arranging data to get the correct solution.

Conclusion

This article is about Interview puzzles and how they can be used in daily life and check our approach in an interview. We have seen two pills each day problem directly related to our lives, and we must have encountered this situation sometimes.

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.

Topics covered
1.
Introduction 
2.
Puzzle Description
3.
Solution
3.1.
Explanation by Example
4.
Frequently Asked Questions
4.1.
How to approach a puzzle interview problem?
4.2.
Why are puzzles asked in interviews?
4.3.
What do you mean by puzzle reasoning?
5.
Conclusion