Problem Variant 1———–
There is a table on which a number of coins are placed. You also know that there are as many coins with Head up as many coins with Tail up. Now you have to divide the coins (number of coins is even) into two equal piles such that number of coins with Heads up and Tails up in either piles be the same. The catch is you are blind folded and you cannot determine the sides (for sure) if you are blinded
[Read More]
40 Pounds in the Balance
Problem You are given a mystery ball and are told that it has a whole-number weight between 1 and 40 lbs (inclusive).
You are then given a balance scale are are allowed to pick four weights, each weighing any whole-number amount. You much choose these weights so that no matter what the mystery ball weighs, you will be able to determine its weight using just the balance scale and these four weights.
[Read More]
Crazy guy in Airplane
Problem People are waiting in line to board a 100-seat airplane. Steve is the first person in the line. He gets on the plane but suddenly can’t remember what his seat number is, so he picks a seat at random. After that, each person who gets on the plane sits in their assigned seat if it’s available, otherwise they will choose an open seat at random to sit in.
The flight is full and you are last in line.
[Read More]
Print a Binary tree in level order with new line after every level
Problem Given a binary tree, you have to print level order traversal of the tree (left child then right child) but every next level has to be printed in next line.
Example
If the given tree is
5 10 15 56 47 12 42 ```Then the output should be 5 10 15 56 47 12 42 ### Solution Here is the approach: 1. Start with a root node. Add it to a new list.
[Read More]
Given an array filled with char elements, find the max length of continuous white space
Problem Given array filled with char elements, can you suggest a most efficient way to find the max length of continuous white space?
Solution Scan the array left to right, keep a count of white space. When you reach a non-whitespace character, check that count against the current max; if it’s higher, it becomes the new max. Set the count back to zero, continue scanning.
Time complexity - O(n)
[Read More]
Monty hall problem - Choose the Correct Door
Problem On the game show “Let’s make a deal”, Monty Hall (the host) walks up to a contestant and gives them $100 unless they want to play “the three doors”. They usually turn down the money and play “the three doors”. Now behind one of the doors is an enourmous cash prize, behind the other too are silly prizes such as a years supply of toilet paper or a goat. So Monty asks this same contestant to pick a door, which they do.
[Read More]
Cigars on Circular Table
Problem Let’s say we play a simple game. I have a circular table and an unlimited supply of identically shaped Cuban cigars. We each take turns placing a cigar on the table without disturbing any other cigars already there in the process and without overlapping any pair of cigars. The winner will be last person to successfully place a cigar on the table subject to the given restrictions. If I give you the option of going first, how would you play in order try and win
[Read More]
Measure 45 minutes
Problem You have two strings of rough non-countinuous composition (in other words these strings are not ideally uniform.) You know that each will take exactly half an hour to burn no matter which end is lit. How can you measure a time interval of 45 minutes with
1.2 match sticks available
2.only one match (which only sustains a flame for a few seconds)
Solution Solution with 2 matches…
Old solution for 2 matches.
[Read More]
Cards with Vowel & Even number
Problem There are 4 cards on a table. Each has a number on one side and a letter on the other. The cards show A,B,1 and 2. Which 2 cards would you turn over to test the rule that “All cards with a vowel on one side have an even number on the other”.
Solution A and 1, since by elimination…
1.we have to take A as if there is a odd no.
[Read More]
Wire Connections
Problem There are 66 wires connecting from the top floor to the ground floor. You can see the ends of the wires but you don’t know which one on the ground floor connects to which one on the top floor. You can tie the ends of several wires together and test the connections at the other end by using a bulb and battery. For example, if you first tie wires A, B, and C together at the ground floor and then go up to the top floor, you will figure out that the bulb will light if you put it between A and B, A and C, or B and C.
[Read More]