Skip to main content

Puzzles-Most Likely Asked in An Interview (Set-3)

Puzzles

1. Sand timer puzzle

You have two sand timers with you. One can measure 7 minutes and the other sand timer can measure 11 minutes. This means that it takes 7 minutes for the sand timer to completely empty the sand from one portion to the other.
You have to measure 15 minutes using both the timers. How will you measure it ?

Solution:

7 Minutes Sand Timer Finished.
Time Remaining in 11 minutes timer - 4 minutes
Reversing the 7 minutes timer - 4 minutes will elapse. 3 Minutes will left.
Once 11 minutes gets over reverse the 11 minutes timer again to use that 3 minutes. 8 Minutes left.
Now Reverse 7 minutes timer to measure 7+8 = 15 minutes.


***************************************************************************************************************************************


2. 17 Horses Puzzle

A farmer wants to divide his 17 horses among his three sons. According to farmer the oldest son should get half of the horses,the middle son should get one third of the horses and the youngest son should get one ninth of the horses.
When their father died they were not able to divide the horses as the result was coming in fractions. As the sons were fighting on how to divide the horses a traveling mathematician came and heard their problem. He proposed a solution with which all the sons got their share in the property without harming any animal. What was the advice given and how the group of horses were divided?

Solution:

Well, this puzzle is interesting. you have to think such that with the solution everybody is happy and no body will suffer a loss.
If we try to devide 17 by 2,3 and 9 then all the results are in fraction so the horses cannot be distributed like this. What will the traveling mathematician do to solve it.
It's simple. He will add his horse to the group of horses. So in total we have 18 horses now. Now let's see the scenario again.
1st son - half of the horses (18/2)=9
2nd son - one third of horses (18/3)=6
3rd son - one ninth of horses (18/9)=2
So in total 17 horses will get distributed among the three sons and the traveling mathematician will take his horse and leave.


***************************************************************************************************************************************


3. 10-digit Number Puzzle

Find a 10-digit number where the first digit is how many zeros in the number, the second digit is how many 1s in the number etc. until the tenth digit which is how many 9s in the number.

Solution: 6210001000


***************************************************************************************************************************************


4. 24 from 8,8,3,3 Puzzle

How can I get the answer 24 by only using the numbers 8,8,3,3.
You can use add, subtract, multiply, divide, and parentheses.

Solution:

8/(3-(8/3))
= 8/(1/3)
= 24


***************************************************************************************************************************************


5. 13 Caves And A Thief Puzzle

There are 13 caves arranged in a circle. There is a thief in one of the caves. Each day the the thief can move to any one of adjacent cave or can stay in smae cave in which he was staying the previous day. And each day, cops are allowed to enter any two caves of their choice.
What is the minimum number of days to guarantee in which cops can catch the thief?

This puzzle was asked in google interview.

Solution: 12

Lets assume the thief is in cave C1 and going clockwise and cops start searching from cave C13 and C12 on your first day.
Cave C13 and C11 on second day,
C13 and C10 on third day and so on till C13 and C1 on 12th day.
So basically the aim is to check C13 everyday so that if thief tries to go anti clockwise you immediately catch it and if goes clockwise cops will catch him in maximum 12 days (this include the case where he remains in Cave C1).


***************************************************************************************************************************************


6. Prisoners and Hats Puzzle

Four prisoners are arrested for a crime, but the jail is full and the jailer has nowhere to put them. He eventually comes up with the solution of giving them a puzzle so if they succeed they can go free but if they fail they are executed.
The jailer puts three of the men sitting in a line. The fourth man is put behind a screen (or in a separate room). He gives all four men party hats. The jailer explains that there are two black and two white hats; that each prisoner is wearing one of the hats; and that each of the prisoners is only to see the hats in front of them but not on themselves or behind. The fourth man behind the screen can't see or be seen by any other prisoner. No communication between the prisoners is allowed.
If any prisoner can figure out and say to the jailer what color hat he has on his head all four prisoners go free. If any prisoner suggests an incorrect answer, all four prisoners are executed. The puzzle is to find how the prisoners can escape, regardless of how the jailer distributes the hats.

This puzzle was asked in google interview.

Solution:

Prisoner A and B are in the same situation they have no information to help them determine their hat colour so they can't answer. C and D realise this.
Prisoner D can see both B and C's hats. If B and C had the same colour hat then this would let D know that he must have the other colour.
When the time is nearly up, or maybe before, C realises that D isn't going to answer because he can't. C realises that his hat must be different to B's otherwise D would have answered. C therefore concludes that he has a black hat because he can see B's white one.


***************************************************************************************************************************************


7. Age of 3 children – Mathematical Puzzle

Two old friends, Lucy and Ellen, meet after a long time.
Lucy: Hey, how are you man?
Ellen: Not bad, got married and I have three kids now.
Lucy: That's awesome. How old are they?
Ellen: The product of their ages is 72 and the sum of their ages is the same as your birth date.
Lucy: Cool But I still don't know.
Ellen: My eldest kid just started taking piano lessons.
Lucy: Oh now I get it.

How old are Ellen's kids?

This puzzle was asked in google interview.

Solution:

This is a very good logical problem. To do it, first write down all the real possibilities that the number on that building might have been. Assuming integer ages one get get the following which equal 72 when multiplied:

2, 2, 18 sum = 22
2, 4, 9 sum = 15
2, 6, 6 sum = 14
2, 3, 12 sum = 17
3, 4, 6 sum = 13
3, 3, 8 sum = 14
1, 8, 9 sum = 18
1, 3, 24 sum = 28
1, 4, 18 sum = 23
1, 2, 36 sum = 39
1, 6, 12 sum = 19

The sum of their ages is the same as your birth date. That could be anything from 1 to 31 but the fact that Lucy was unable to find out the ages, it means there are two or more combinations with the same sum. From the choices above, only two of them are possible now. For any other number, the answer is unique and the Lucy would have known after the second clue. So he asked for a third clue. The clue that the eldest kid just started taking piano lessons is really just saying that there is an "oldest", meaning that the younger two are not twins.

2, 6, 6 sum(2, 6, 6) = 14
3, 3, 8 sum(3, 3, 8 ) = 14

Hence, the answer is that the elder is 8 years old, and the younger two are both 3 years old. The answer is 3, 3 and 8.


***************************************************************************************************************************************


8. Hats And IIT Students

The riddle is Nine IIT students were sitting in a classroom. Their professor wanted them to test. Next day the professor told all of his 9 students that he has 9 hats, The hats either red or black color. He also added that he has at least one hat with red color and the no. of black hats is greater than the no. of red hats. The professor keeps those hats on their heads and ask them tell me how many red and black hats the professor have? Obviously students can not talk to each other or no written communication, or looking into each other eyes; no such stupid options and no tricks.
Professor goes out and comes back after 20 minutes but nobody was able to answer the question. So he gave them 10 more minuets but the result was the same. So he decides to give them final 5 minutes. When he comes everybody was able to answer him correctly.
So what is the answer? and why?

This puzzle was asked in google interview.

Solution:

After first interval of 20 minutes :
Lets assume that their is 1 hat of red color and 8 hats of black color. The student with red hat on his head can see all 8 black hats, so he knows that he must be wearing a red hat.
Now we know that after first interval nobody was able to answer the prof that means our assumption is wrong. So there can not be 1 red and 8 black hats.
After second interval of 10 minutes :
Assume that their are 2 hats of red color and 7 hats of black color. The students with red hat on their head can see all 7 black hats and 1 red hat, so they know that they must be wearing a red hat.
Now we know that after second interval nobody was able to answer the prof that means our assumption is again wrong. So there can not be 2 red and 7 black hats.
After third interval of final 5 minutes :
Now assume that their is 3 hats of red color and 6 hats of black color. The students with red hat on their head can see all 6 black hats and 2 red hats, so they know that they must be wearing a red hat.
Now we know that this time everybody was able to answer the prof that means our assumption is right.So there are 3 red hats and 6 black hats.Now as everybody gave the answer so there can be a doubt that only those 3 students know about it how everybody came to know ?
Then here is what i think, the professor gave them FINAL 5 minutes to answer, so other guys will think that the professor expects the answer after 3rd interval (according to prof it must be solved after 3 intervals), so this is the clue for others.


***************************************************************************************************************************************


9. 25 horses and 5 lanes

There are 25 horses and 5 lanes. You have no idea about which horse is better than other. Find in minimum possible races, the first three fastest running horses.

This puzzle was asked in microsoft interview

Solution:

We will have 5 races with all 25 horses
Let the results be
u1,u2,u3,u4,u5
v1,v2,v3,v4,v5
x1,x2,x3,x4,x5
y1,y2,y3,y4,y5
z1,z2,z3,z4,z5

Work through a process of elimination:

Where u1 faster than u2 , u2 faster than u3 etc and We need to consider only the following set of horses
u1,u2,u3
v1,v2,v3
x1,x2,x3
y1,y2,y3
z1,z2,z3

Race 6
We race u1,v1,x1,y1,z1
Let speed(u1)>speed(v1)>speed(x1)>speed(y1)>speed(z1)

We get u1 as the fastest horse
We can ignore y1,y2,y3,z1,z2 and z3 automatically since those can not be in the top 3.

Now we left with
u2,u3,
v1,v2,v3,
x1,x2,x3,

Race 7
Race u2,u3,v1,v2 and x1 (x2,x3 is ignored since v1,x1 are faster than both, so obvious choices are u2,u3,v1,v2 and x1)
The first and second will be second and third of the whole set

So we need minimum of 7 races to find the 3 fastest horses.


***************************************************************************************************************************************


10. Heavy and Light Balls Puzzle

You have 2 ball of each A,B,C colors and each color have 1 light and 1 heavy ball. All light balls are of same weight same goes for heavy. Find out weight type of each ball in minimum chances. You can use a two sided balance system (not the electronic one).

This puzzle was asked in many interviews - Drishti-soft, Yahoo, Infoedge.

Solution:

Simply, you can check by taking 2 balls of same color. Now, comparing those balls with other balls but this will take 3 chances for each color type ball.
Answer is 2 chances.
So, Make a table for all conditions for all 6 balls that will help in understanding and solving this problem.
A1,A2,B1,B2,C1,C2
First weight A1,B1 and B2,C1 -> 3 cases equal ,left is heavy or left is light.
Case 1:
Equal, if equal weight simply B1,B2 will solve the problem.

Case 2:
If A1+B1 > B2+C1, then we know B1 > B2. Also just that A1>=C1.

Next compare A1,B1 and A2,C1
If A1+B1 = A2+C1 means A2 is heavy and A1=C1 light
If A1+B1 > A2+C1 means A2 is light and A1=C1 heavy
A1+B1 < A2+C1 will not happen because B1 is any way heavier.

Case 3:

If A1+B1 > B2+C1

Similar to above case we can check it.


***************************************************************************************************************************************


Developer:
Shubham Chaudhary

Comments

Popular posts from this blog

How to Create a Namespace in Aerospike Database

                      T his post is about creating a namespace in Aerospike. I could not find any concrete method to create a namespace like create database in MySQL and MongoDB. So I am suggesting a way to create a namespace in Aerospike Database. Step-1: Locate config file aerospike.conf and open it in your favorite editor and make sure you have permission to modify the file. In my system the path of file /etc/aerospike/aerospike.conf (Default in Ubuntu). Here the content of the file. # Aerospike database configuration file. service { user root group root paxos-single-replica-limit 1 # Number of nodes where the replica pidfile /var/run/aerospike/asd.pid service-threads 4 transaction-queues 4 transaction-threads-per-queue 4 proto-fd-max 15000 } logging { # Log file must be an absolute path. file /var/log/aerospike/aerospike.log { context any info } } network { service { address any port 3000 } heartbeat { mode multicast address 239.1.99.222 p

java.lang.IllegalArgumentException: Could not instantiate implementation: org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftStoreManager

If you are trying to get started with Janus Graph with Apache Cassandra. You may get the following error. Caused by: org.janusgraph.diskstorage.TemporaryBackendException: Temporary failure in storage backend at org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftStoreManager.getCassandraPartitioner(CassandraThriftStoreManager.java:219) ~[janusgraph-cassandra-0.2.0.jar:na] at org.janusgraph.diskstorage.cassandra.thrift.CassandraThriftStoreManager.<init>(CassandraThriftStoreManager.java:198) ~[janusgraph-cassandra-0.2.0.jar:na] ... 48 common frames omitted Caused by: org.apache.thrift.transport.TTransportException: java.net.ConnectException: Connection refused (Connection refused) at org.apache.thrift.transport.TSocket.open(TSocket.java:187) ~[libthrift-0.9.2.jar:0.9.2] at org.apache.thrift.transport.TFramedTransport.open(TFramedTransport.java:81) ~[libthrift-0.9.2.jar:0.9.2] at org.janusgraph.diskstorage.cassandra.thrift.thriftpool.CTConnectionFactory.makeR

com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server

If you are trying to connect Mongo DB Server and it insanely throwing following error. com.mongodb.MongoTimeoutException : Timed out after 1000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=192.168.1.10:27010, type=UNKNOWN, state=CONNECTING, exception={ com.mongodb.MongoSecurityException: Exception authenticating MongoCredential {mechanism=null, userName='user123', source='admin', password=<hidden>, mechanismProperties={}}}, caused by {com.mongodb.MongoCommandException: Command failed with error 18 : 'Authentication failed.' on server 192.168.1.10:27010 . The full response is { "ok" : 0.0, "code" : 18, "errmsg" : "Authentication failed." }}}] If you start looking the error content First you encounter with Timeout Exception which may mislead you. It is basically an authentication error. I