Skip to main content

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

Puzzles

1. King Octopus and Servants

King Octopus has servants with six, seven, or eight legs. The servants with seven legs always lie, but the servants with either six or eight legs always say the truth.

One day, 4 servants met :
The blue one says: Altogether we have 28 legs.
The green one says: Altogether we have 27 legs.
The yellow one says: Altogether we have 26 legs.
The red one says: Altogether we have 25 legs.

What is the colour of the servant that says the truth?

Solution:

The green one is telling the truth.
Lets assume that one of them is telling the truth and then try to prove that. Since the four are disagreeing then 3 must be lying.
Lets say blue is telling the truth: so the blue one has either 6 or 8 legs. And each of the other octopus is lying hence has 7 legs. So our total legs becomes: 6 + 7 + 7 + 7 = 27 legs or 8 + 7 + 7 + 7 = 29 legs. But since blue said altogether we have 28 legs, we know he is lying.
If you follow this same logic for all of them, you realize that only the Green octopus can be telling the truth as the number of legs adds up.


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

2. Prisoner and two Doors Puzzle

Court takes decision to relax the sentence given to criminal if he can solve a puzzle. Criminal has to take decision to open one of the doors.
Behind each door is either a lady or a tiger. They may be both tigers, both ladies or one of each.
If the criminal opens a door to find a lady he will marry her and if he opens a door to find a tiger he will be eaten alive. Of course, the criminal would prefer to be married than eaten alive.
Each of the doors has a statement written on it.
The statement on door one says, "In this room there is a lady, and in the other room there is a tiger." The statement on door two says,"In one of these rooms there is a lady, and in one of these rooms there is a tiger."
The criminal is informed that one of the statements is true and one is false. Which door should the criminal open?

Solution:

Criminal should open door number 2.
How?
Lets assume statement on the first door is true then second statement will also be true(as there will be a lady in one door and a tiger in other door), but as we already know that only one statement can be true, so first statement can not be true.
Now if first statement is false, it implies these possible scenarios

Door 1 Door 2
Tiger Tiger
Lady Lady
Tiger Lady
But as second statement is true, so it means behind one of the door there is a lady and in other door there is a tiger so options with both lady and both tigers are ruled out and only third option remains valid, thus the criminal should choose door number 2.


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

3. 100 Wrong Statements puzzle

There are 100 statements.
1st one says : at least one is wrong.
2nd one says : at least two are wrong.
3rd one says : at least three are wrong.
4th one says : at least four are wrong.
and so on.
100th one says : at least 100 are wrong.
How many statements are actually wrong and how many actually right ?

Solution:

100th statement is definitely wrong because it says at least 100 are wrong.
But if that is correct, then 100 statement itself cannot be right.
=> 100th statement is wrong and
=> 1st statement is correct.

99th statement cannot be correct because if it were correct,
then two statements would become correct (1st and 99th itself.)

But 99th statement says that atleast 99 are wrong.
=> 99th is wrong and
=> 2nd is correct.
calculating so on…
50 statements are right (the first 50 ones)
remaining 50 statements are wrong.


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

4. Cashier's Puzzle

Problem: An engineer goes to a bank with a check of $200 and asks the cashier "Give me some one-dollar bills, ten times as many twos and the balance in fives!".
What will the cashier do?

Solution:

The smallest amount of one-dollar and two-dollar bills the cashier may give to the old man is 1x1 + 10x2 = 21.
He must give the old man a multiple of 21 i.e. 21 or 42 or 63 or 84 or 105 or 126 or 147 or 168 or 187 without exceeding 200. Out of all these numbers only 105 can be added to a multiple of 5 to sum up to make 200 altogether.
So he must give the balance of 95 in five-dollar bills.
Therefore, the cashier must give 5 one-dollar bills, 50 two-dollar bills and 19 five-dollar bills.

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

5. Supersonic bee and trains

Two trains enter a tunnel 200 miles long, traveling at 100 mph at the same time from opposite directions. As soon as they enter the tunnel a supersonic bee flying at 1000 mph starts from one train and heads toward the other one. As soon as it reaches the other one it turns around and heads back toward the first, going back and forth between the trains until the trains collide in a fiery explosion in the middle of the tunnel. How far did the bee travel?

Solution: 1000 miles

This puzzle is very easy.You only need to think into right direction.
Forget about the path of bee.We know the speed of bee and we have to calculate distance so we only need time.
distance = sped x time
We can calculate the time before collision by simple physics law of relative velocity.
time = 200/(100+100)
time = 1 hrs
so distance = 1000 x 1 = 1000 miles

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

6. Blind bartender's problem

Four glasses are placed on the corners of a square table. Some of the glasses are upright (up) and some upside-down (down). A blindfolded person is seated next to the table and is required to re-arrange the glasses so that they are all up or all down, either arrangement being acceptable, which will be signalled by the ringing of a bell. The glasses may be re-arranged in turns subject to the following rules. Any two glasses may be inspected in one turn and after feeling their orientation the person may reverse the orientation of either, neither or both glasses. After each turn the table is rotated through a random angle. The puzzle is to devise an algorithm which allows the blindfolded person to ensure that all glasses have the same orientation (either up or down) in a finite number of turns. The algorithm must be non-stochastic i.e. it must not depend on luck.

Solution:

* On the first turn choose a diagonally opposite pair of glasses and turn both glasses up.

* On the second turn choose two adjacent glasses. At least one will be up as a result of the previous step. If the other is down, turn it up as well. If the bell does not ring then there are now three glasses up and one down(3U and 1D).

* On the third turn choose a diagonally opposite pair of glasses. If one is down, turn it up and the bell will ring. If both are up, turn one down. There are now two glasses down, and they must be adjacent.

* On the fourth turn choose two adjacent glasses and reverse both. If both were in the same orientation then the bell will ring. Otherwise there are now two glasses down and they must be diagonally opposite.

* On the fifth turn choose a diagonally opposite pair of glasses and reverse both. The bell will ring for sure.



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

7. Squares on a chess board?

How many squares are on a chess board?

Solution: 204

If you thought the answer is 64, think again! :-)
How about all the squares that are formed by combining smaller squares on the chess board (2x2, 3x3, 4x4 squares and so on)?
A 1x1 square can be placed on the chess board in 8 horizontal and 8 vertical positions, thus making a total of 8 x 8 = 64 squares. Let's consider a 2x2 square. There are 7 horizontal positions and 7 vertical positions in which a 2x2 square can be placed. Why? Because picking 2 adjacent squares from a total of 8 squares on a side can only be done in 7 ways. So we have 7 x 7 = 49 2x2 squares. Similarly, for the 3x3 squares, we have 6 x 6 = 36 possible squares. So here's a break down.

1×1 8 x 8 = 64 squares
2×2 7 x 7 = 49 squares
3×3 6 x 6 = 36 squares
4×4 5 x 5 = 25 squares
5×5 4 x 4 = 16 squares
6×6 3 x 3 = 9 squares
7×7 2 x 2 = 4 squares
8×8 1×1 = 1 square 1^2 + 2^2 + 3^2 + . . . n ^2

Total = 64 + 49 + 36 + 25 + 16 + 9 + 4 + 1 = 204 squares

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

8. The Fox and The Duck Puzzle

A duck, pursued by a fox, escapes to the center of a perfectly circular pond. The fox cannot swim, and the duck cannot take flight from the water. The fox is four times faster than the duck. Assuming the fox and duck pursue optimum strategies, is it possible for the duck to reach the edge of the pond and fly away without being eaten? If so, how?

This is the classical puzzle asked in microsoft interview

Solution:

From the speed of the fox it is obvious that duck cannot simply swim to the opposite side of the fox to escape.

Fox can travel 4r in the time duck covers r distance. Since fox have to travel half of the circumference Pi*r and Pi*r < 4r

So how could the duck make life most difficult for the fox? If the duck just tries to swim along a radius, the fox could just sit along that radius and the duck would continue to be trapped.

At a distance of r/4 from the center of the pond, the circumference of the pond is exactly four times the circumference of the duck's path.

Let the duck rotate around the pond in a circle of radius r/4. Now fox and duck will take exact same time to make a full circle. Now reduce the radius the duck is circling by a very small amount (Delta). Now the Fox will lag behind, he cannot stay at a position as well.

Say, the duck circles the pond at a distance (r/4 - e), where e is an infinitesimal amount. So as the duck continues to swim along this radius, it would slowly gain some distance over the fox. Once the duck is able to gain 180 degrees over the fox, the duck would have to cover a distance of 3r/4 + e to reach the edge of the pond. In the meanwhile, the fox would have to cover half the circumference of the pond (i.e the 180 degrees). At that point,

(pi * r ) > 4 * (3r/4 + e)

So time taken to travel 3r/4 is quicker than 3.14*r at four times the speed.(0.14*r distance is left)

The duck would be able to make it to land and fly away.


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

9. River Crossing Puzzle

Sailor Cat needs to bring a wolf, a goat, and a cabbage across the river. The boat is tiny and can only carry one passenger at a time. If he leaves the wolf and the goat alone together, the wolf will eat the goat. If he leaves the goat and the cabbage alone together, the goat will eat the cabbage. How can he bring all three safely across the river?

Solution:

he trick to this puzzle is that you can keep wolf and cabbage together. So the solution would be
The sailor will start with the goat. He will go to the other side of the river with the goat. He will keep goat there and will return back and will take cabbage with him on the next turn. When he reaches the other side he will keep the cabbage there and will take goat back with him.
Now we will take wolf and will keep the wolf at the other side of the river along with the cabbage. He will return back and will take goat along with him. This way they all will cross the river.

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

10. 8 Balls Puzzle

You have 8 balls. One of them is defective and weighs less than others. You have a balance to measure balls against each other. In 2 weighing, how do you find the defective one?

Solution:

Defective ball is light

Make three Groups G1 - 3 balls G2 - 3 balls G3 - 2 balls

First weight G1 and G2 if G1 = G2 then defective ball in G3 , weigh the the 2 balls in G3 if EQUAL then 3rd ball of G3 is defective else whichever lighter in 1st or 2nd is defective ball

else if G1 < G2 defective ball in G1 weigh 1 and 2 ball of G1 if EQUAL then 3rd ball of G1 is defective else whichever lighter in 1st or 2nd is defective ball

else if G1 > G2 defective in G2
Again in 1 comparison we can find the odd ball.

So by following above steps in 2 steps, lighter ball can be find out.

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

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