Puzzles for the interview which every one should read once


Hi, This is Shubham Mishra a ROR, iOS, Python developer,  this is the part of Algorithm analysis exploration journey.  In this post we will discuss about the Awesome puzzles that may be asked in the interview process, whether it may be for any position or the role. Even if not for the interview but still you will enjoy to solve the below puzzles.


The opportunity to bring unique insight to solving business issues will give you an immense advantage over other applicants. Only with daily practice and continuous effort can these capacities be established.

For me it's like intellectual training for solve puzzles. I do it on a regular basis, and have progressed equally over time. I 'm sharing some of the trickiest & head scratching questions I've experienced in my journey to help you attain the ability. Such questions were aimed at organisations such as Goldman Sachs, Amazon , Facebook, JP Morgan etc.


The Bus Chaos

Chaos in the bus. There is a bus with 100 seats numbered (marked from 1 to 100). One hundred people waiting in a queue. Individuals are also numbered 1 to 100.

Individuals board a bus from 1 to n in order. The rule is to check if the person 'i' is boarding the bus, if the seat 'i' is empty. He sits then if it was empty, otherwise he randomly takes up an empty seat and sits there. Provided that the 1st person randomly chooses seat, determine the probability that the 100th person will sit in his place , i.e. 100th seat.



Answer: The final result is the probability that the last individual will end up in his proper position is exactly 1/2

Reason:  Mainly, remember that the last person's fate is decided by the moment the first or the last seat is chosen! It is because either the first seat or the last seat would be at the last person. Any other seat would automatically be taken by others till the last guy gets the chance to choose it.
As the first or the last step of the choice is equally likely to be taken at each step of the choice, the last person will either get the first or the last one with the same probability: 1/2.




Mad men in a circle

N individuals stand in a circle. They 're numbered in clockwise order from 1 to N. Each of them carries a pistol and is able to shoot a individual to his left.

Beginning from person 1, they keep shooting in accordance to e.g. for N=100, individual 1 shoots individual 2, then individual 3 shoots individual 4, then individual 5 shoots individual 6 ........ then individual 99 shots individual 100, then individual 1 shoots individual 3, then individual 5 shoots individual 7 ...... and it continues until all are dead but one. What's the last person's index?



Answer

Let's write 100 in binary, which is 1100100 then have the complement which is 11011 and it is 27. Deduct the complement from the actual number. So 100 – 27 = 73.

Do it out for 50 people. 50 = 110010 in binary.

Complement is 1101 = 13. Hence, 50 – 13 = 37

For the number in form 2^n, this will be the first person. Let’s take an example:

64 = 1000000

Complement = 111111 = 63.

64-63 = 1.

You can apply this for any ’n’.





These children deserve badges

The school has 10 extremely smart boys: A, B , C , D, E , F, G , H, I and Sam. At 8:58 am, they sprint into class laughing, just two minutes before the playtime begins, and a stern-looking teacher stops them: Mr Rabbit.

Mr Rabbit finds mud on their faces in A, B, C and D. He, being a teacher who thinks his point of view is always right, and works only to impose laws rather than to care about the world which should be, strikes at the poor children.

“Silence!”, he shouts. “Nobody will talk. All of you who have mud on your faces, get out of the class!”. The children looking at each other. Growing child could see if the other children had mud on their faces but couldn't see their own faces. No-one leaves the class.

"I told, you everybody who has mud on your faces, have to get out of classroom!"

No-one leaves anyway. After 5 more tries, the bell rings at 9 and Mr Rabbit exasperatedly yells: "I could see well that in at least one of you children has mud on his face! ”.

The kids are grinning, believing their ordeal is soon over. Sure enough, after some more bawling of "Everyone of you in the mud on your hands, get out of classroom! ". A, B, C and D comes out of the class.

Illustrate how A, B , C and D thought their faces were dirty. What prompted kids to grin? Everyone knew he had at least one kid on his hands with dirt. Help with a reasonable argument that prior to Mr Rabbit's exasperated shouting at 9, a kid did not know, but that the kid knew right after him.

Answer

They realised, after the first shout from Mr Rabbit, that at least one boy gets mud on his face. But, if it was just a boy, then the kid would know he 'd got mud on his face and go out after a yell.

They realised that at least two boys had mud on their faces, because no one moved out after one yell. If it were exactly two boys, those boys could know (they would are only seeing the muddy face of one other so they would realize that their face is muddy too) and then go out after the next shout.

Since no one moved out since the second shouting, it means three muddy faces are atleast and the like, well after fourth shouting, A, B , C and D will go out of class.

This clarification will leave an open many questions. Everyone knew that at least three others had mud on their hands, so why had they to wait for Mr. Rabbit's first-place shout? Why did they still have to go through the all four shouts after that?

A important principle emerges of general knowledge in multi-agent reasoning. Everyone realizes there have been at least three muddy faces but they would not act on this knowledge together without realising that someone else recognises that too. But everyone knows that everyone knows that, and so forth. That is what we are going to examine. It needs a bit of creativity, so be prepared.

A thinks there's mud on their faces for B , C and D. A doesn't know if B suspects there's mud on three people's faces. A suspects B thinks that there's mud on two people's faces. But A can't possibly expect to act on that knowledge because A doesn't know whether B knows that C understands there are 2 persons on their faces with mud. If you think that all of this is uselessly complicated, consider:

A may conceive of a universe where he has no dirt on his face. (Call this universe A) In the case of A, A can imagine B having a life where both A and B have no mud on their faces. (Call universe AB)

A can picture a universe where C portrays that D portrays no one has mud on their faces. (Call it ABCD universe). And when Mr Rabbit originally screamed, it may have been because no one was going out when it was possible to have an ABCD universe in which no one would go out anyway.

And here's a phrase that alters after a screaming from Mr. Rabbit. World ABCD can not, i.e. A can not envision a world where C portrays that D portrays no one has mud on their faces. So now in ABC universe, D suspects he 's got mud on his face. And in ABD culture, C knows he's got mud on his face and so forth.




Enjoying 😊😊! this interview Puzzles: Comment for any doubts in the comment section, also you can share this interview puzzle post to your friends. Wait the interview puzzle is yet not ends but more to go.




4 Points inside a circle

Thinking of a unit sphere. What is the probability that the center (of the sphere) lies inside the tetrahedron (/polygon) created by those 4 points?


Answer

Let A, B and C be spontaneous sphere nodes or you can say points, with diameters of Aa, Bb, and Cc.

The rounded (small) triangle abc is similar to the abc, bca and cab hemispheres (at which abc notation indicates the hemisphere cut off by the broad circle between a and b and containing point c, etc.), thus the probability that another random point, D, will lie on this triangle is:

1/2 x 1/2 x 1/2 = 1/8

Note: (For the centre to present in the tetrahedron D must be lie in the triangle i.e the opposite hemisphere of ABC)







Life and Fortune

You are trapped by gangsters and forced to play a game to decide if you will live or die. The game is simplistic.

There would be a card deck, and you must both pick a new card. You could see at the cards of one another but not the cards that you have selected. You both will survive if both think the card they've selected is correct. Otherwise they both will die.

What is the likelihood of you sustaining or you can say, surviving if you play these games optimally with your friend?



Answer

We believe, A and B select a card from the a deck at discrete points. A can see the card from B, and inversely. So, A knows (s)he didn't pick the card from B, but aside from all this, (s)he believes the card is equally likely to be any of the other 51 cards. So, if A suspects the card from B, then they lose. But if A predictions some other card, then there is a 1/51 chance that A will be correct. This also means absolute probability of success <= 1/51

A's goal currently is to say any card other than B's card which offers B the most knowledge regarding B's card itself. So, they should prepare as follows beforehand:

Notice the Clubs 1-13 Card series, Diamonds 1-13, Hearts 1-13, Spades 1-13. In this series, a must say the card after B's card. (If A tells 4 of Hearts, it means B has 3 of Hearts. If A tells Ace of Clubs, B means King of Spades)

Through A's guess, that is usually distinct from B's card, B gets to realize specifically which card (s) she's got and can always estimate correctly. As well as the probability of winning is 1/51, which is the most attainable.





Chameleons turn up on the date

Thirteen purple, 15 yellow and 17 maroon chameleons live on one island. When two diffrent coloured chameleons intersect, they both transform into the third colour. Is there a series of meetings in pairs in which all chameleons have the same colour?
Answer

Now let's understand and solve the puzzle with some mathematical equations.
Let <pc, yc, mc> signify a collection of chameleons with p purple, yellow and m maroon. Is it possible to turn population < 13, 15, 17 > into population < 45, 0, 0 > or < 0, 45, 0 > or < 0, 0, 45 > through a sequence of pairs of meetings?

Based on above we can create a function below:
F(pc, yc, mc) = (0pc + 1yc + 2mc) mod 3

An noteworthy aspect of 'F' is that its quality should never alter upon meeting in pairs since:
F(pc, yc, mc) = F(pc-1, yc-1, mc+2) = F(pc-1, yc+2, mc-1) = F(pc+2, yc-1, mc-1)

Now F(13, 15, 17) becomes equal to 1. However,

F(45, 0, 0) = F(0, 45, 0) = F(0, 0, 45) = 0**

It ensures no series of pairly meetings under which all chameleons would have the same colour.




Ok great, we are done with this post,  

Now if you like my way of talk, lets explore more blogs written by me and my inner knowledge,

Get to know answers for common search on Google : A blog for posts which can help you for daily life problems, such as where to get free images, Topic suggestion for the blog.

Computer Science algorithms and other knowledge share : A blog for posts such as best search algorithm, Top interview questions for diffrent technologies, knowledge share for some frameworks or programming languages for the interview or in general terms.

My ideas to solve real world problems : A blog where me shared and presented my ideas to solve a real world problems, this will be interesting for me.

Future of computer science technology discussed : A blog where me discussed about the future of computer science and new technologies which will change our way for looking to solve problems.

Ruby on Rails Web development Blog : As the name suggest, it is the blog for sharing few knowledge about RoR web development framework.


Liked my blogs, wanna to connect:

LinkedIn   GitHub  |  HackerEarth   ResearchGate  |  Twitter  |  Facebook  |  StackOverflow

Thanks for reading this post, Have a good day :)
















Comments

Popular posts from this blog

Amazon Interview question from leetcode coding problem 1

Use ChatGPT for improve your coding quality