In a small town in the United States, a teenage boy asked his parents if he could go to a friend's party. His parents agreed, provided that he was back before sunrise. He left the house that evening clean-shaven and when he returned just before the following sunrise his parents were amazed to see that he had a fully grown beard. What happened?
The small town was Barrow in Alaska, the northernmost town in the United States. When the sun sets there in the middle of November, it does not rise again for 65 days. That allowed plenty of time for the boy to grow a beard before the next sunrise.
See also best riddles or new riddles.logicprobability
You and a friend are standing in front of two houses. In each house lives a family with two children.
"The family on the left has a boy who loves history, but their other child prefers math," your friend tells you.
"The family on the right has a 7-year old boy, and they just had a new baby," he explains.
"Does either family have a girl?" you ask.
"I'm not sure," your friend says. "But pick the family that you think is more likely to have a girl. If they do have a girl, I'll give you $100."
Which family should you pick, or does it not matter?
You should pick the house on the left. Specifically, there is a 2/3 chance that the family on the left has a girl, whereas there's only a 1/2 chance that the house on the right has a girl.
This is a very counterintuitive riddle. It seems like there should always be a 1/2 chance that a given child is a girl. And in fact there is. The key word there is "given". Because we are not asking about a "given" child for the house on the left. We are asking about what could be either child. Whereas for the house on the right, we are asking about a "given" child...specifically, we're asking about the younger child.
There are 3 possibilities for the children in the first house:
There is no "Girl, Girl" option because we know the house on the left has at least one boy. Since each of these 3 options is equally likely, and 2 of them have one girl, there is a 2/3 chance of there being a girl in the house on the left.
For the house on the right, because we already know the older child is a boy, there are only two possibilities:
And as we can see, there is a 1/2 chance for the house on the right having a girl.logicmath
Two words are anagrams if and only if they contain the exact same letters with the exact same frequency (for example, "name" and "mean" are anagrams, but "red" and "deer" are not).
Given two strings S1 and S2, which each only contain the lowercase letters a through z, write a program to determine if S1 and S2 are anagrams. The program must have a running time of O(n + m), where n and m are the lengths of S1 and S2, respectively, and it must have O(1) (constant) space usage.
First create an array A of length 26, representing the counts of each letter of the alphabet, with each value initialized to 0. Iterate through each character in S1 and add 1 to the corresponding entry in A. Once this iteration is complete, A will contain the counts for the letters in S1. Then, iterate through each character in S2, and subtract 1 from each corresponding entry in A. Now, if the each entry in A is 0, then S1 and S2 are anagrams; otherwise, S1 and S2 aren't anagrams.
Here is pseudocode for the procedure that was described:
def areAnagrams(S1, S2)
A = new Array(26)
for each character in S1
arrayIndex = mapCharacterToNumber(character) //maps "a" to 0, "b" to 1, "c" to 2, etc...
A[arrayIndex] += 1
for each character in S2
arrayIndex = mapCharacterToNumber(character)
A[arrayIndex] -= 1
for (i = 0; i < 26; i++)
if A[i] != 0
A man entered his house and was about to hang up his coat when he heard his wife shout;
"No John! Don’t do it!"
There was a shot and he could hear his wife fall down. When he entered the kitchen he saw his wife and the gun lying on the floor. There was a police officer, a doctor, and a lawyer standing next to her. Peter immediately knew that the police officer had shot her.
But how did he come to know?
The police officer was the only man while the doctor and lawyer were ladies. Peter on a second glance would also read the police officer’s name on his name tag as "John". Peter’s wife was saying, "No John! Don’t do it!" to the police officer and the police officer shot her anyway.cleanlogicshort
If a boy is 12 and his brother is 13, how is the 12 year old older than his brother?
His brother is 13 months.
Dodge was staying with Cousin Jamie in Jamie's lakeside cabin. They were setting up Jamie's will. As Dodge was Jamie's closest living relative, much of Jamie's estate was being left to him. One day, Jamie went to Dr Dodge very disturbed. "Doctor," he began, "I have just found out that a man named Georgio wants to get me. He will be here very soon. Where will I go? Where can I hide? If he finds me in here, he will surely kill me. I do not have time to leave this clearing and go farther into the woods."
Dr Dodge thought for a moment, and then grabbed a 5' long bamboo pole, with a diameter the size of a quarter. "Jamie, follow me out to the lake. This lake is 4' deep. If you lie on the bottom of the lake and breathe through this pole, Georgio will never find you. I will be in the bulrushes with a shotgun, and I will shoot him when he comes. I will swim down to find you when he is gone." Jamie consented, and lay down on the bottom of the lake with the bamboo pole in his mouth. A few hours later, a ranger passed by. He found Jamie's body, dead. Dr Dodge told the police of the circumstance, and that Jamie had probably panicked, and died. Police arrested Dr Dodge, on the charges of murdering Jamie. Why?
The bamboo pole did not have any cracks or holes. Its opening was above water the whole time.
Jamie died of carbon dioxide poisoning. The pole was 5' long, but only the size of a quarter. The first time he breathed in, he breathed oxygen. When he exhaled, the air could not travel 5' before he breathed in again. He was just breathing what he exhaled. Before long, all he was breathing was carbon dioxide. He died of CO2 poisoning. Doctor Doge was the one who told him to use the pole, therefore the cause of his death. Dodge is a DOCTOR, and therefore knows about the CO2. Dodge did murder Jamie. His motive: the money in the will.logicmathshort
Can you arrange four 9's and use of atmost 2 math symbols, make the total be 100?
99 / .99logicprobability
Your friend shows you two jars, one with 100 red marbles in it, the other with 100 blue marbles in it.
He proposes a game. He'll put the two jars behind his back and tell you to pick one of them at random. You'll then close your eyes, he'll hand you the jar you picked, and you'll pick a random marble from that jar.
You win if the marble you pick is blue, and you lose otherwise.
To give you the best shot at winning, your friend gives you the two jars before the game starts and says you can move the marbles around however you'd like, as long as all 200 marbles are in the 2 jars (that is, you can't throw any marbles away).
How should you move the marbles around to give yourself the best chance of picking a blue marble?
Put one blue marble in one jar, and put the rest of the marbles in the other jar. This will give you just about a 75% chance of picking a blue marble.funnylogic
Presume that you do not know what a rhino looks like. Now the question goes like this: If one day while walking in a forest with two of your close friends, one friend shows you an elephant and tells that this is a rhino, and another friend shows you a hippopotamus and tells you that this is rhino, who would you believe and why?
I told you that you do not know what a rhino looks like, not that you are unaware of what a hippo and elephant look like. So you shouldn't believe either of them.logicshort
Every time you lose something, you always find it in the very last place you would look. Why is this?
It is the last place you would look because once you find it there is no need to keep looking.interviewlogicmath
Three ants are sitting at the three corners of an equilateral triangle. Each ant starts randomly picks a direction and starts to move along the edge of the triangle. What is the probability that none of the ants collide?
So let’s think this through. The ants can only avoid a collision if they all decide to move in the same direction (either clockwise or anti-clockwise). If the ants do not pick the same direction, there will definitely be a collision. Each ant has the option to either move clockwise or anti-clockwise. There is a one in two chance that an ant decides to pick a particular direction. Using simple probability calculations, we can determine the probability of no collision.
P(No collision) = P(All ants go in a clockwise direction) + P( All ants go in an anti-clockwise direction) = 0.5 * 0.5 * 0.5 + 0.5 * 0.5 * 0.5 = 0.25