There are ten people in a house. Everybody wants to make a hand shake with only people shorter than themselves. Assume everybody is different in height. How many hand shakes are made?
0, because a taller person wants to shake hands with a shorter person. But the shorter person doesn't want to shake hands with him.
The day before two days after the day before tomorrow is Saturday. What day is it today?
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
Many years ago a wealthy old man was near death. He wished to leave his fortune to one of his three children. The old man wanted to know that his fortune would be in wise hands. He stipulated that his estate would be left to the child who would sing him half as many songs as days that he had left to live.The eldest son said he couldn't comply because he didn't know how many days his father had left to live and besides he was too busy. The youngest son said the same thing. The man ended up leaving his money to his third child a daughter. What did his daughter do?
Every other day, the daughter sang her father a song.short
Take away my first letter, and I still sound the same. Take away my last letter, I still sound the same. Even take away my letter in the middle, I will still sound the same. I am a five letter word. What am I?
What is the best thing to take when you’re run over?
The license plate of the vehicle that hit you.funny
A man came to visit at a convent while the superior mother was out of town. He left before she returned, and was careful to leave nothing behind. The nuns said nothing about his visit, so how did the superior mother figure out that a man had been there?
Because a toilet seat was up.logic
A number of people have broken the sound barrier, either in a super-fast car, or in nice fancy planes. However, hundreds of years ago it was broken on horseback. How?
Many people who ride horses carry whips. They crack the whip while they ride the horse. When a whip is cracked, the tip travels faster than the speed of sound, which makes the loud snap. It actually creates a miniature sonic boom of sorts. The whip breaks the sound barrier, thus, it was broken on horseback.logic
You are on your way to visit your Grandma, who lives at the end of the valley. It's her anniversary, and you want to give her the cakes you've made. Between your house and her house, you have to cross 5 bridges, and as it goes in the land of make believe, there is a troll under every bridge! Each troll, quite rightly, insists that you pay a troll toll. Before you can cross their bridge, you have to give them half of the cakes you are carrying, but as they are kind trolls, they each give you back a single cake.
How many cakes do you have to leave home with to make sure that you arrive at Grandma's with exactly 2 cakes?
At each bridge you are required to give half of your cakes, and you receive one back. Which leaves you with 2 cakes after every bridge.logicshort
One day, Emperor Akbar posed a question to Birbal. He asked him what Birbal would choose if he offered either justice or a gold coin.
"The gold coin," said Birbal without hesitation.
On hearing this, Akbar was taken aback. "You would prefer a gold coin to justice?" he asked, not believing his own ears.
"Yes," said Birbal.
The other courtiers were amazed by Birbal's display of idiocy. They were full of glee that Birbal had finally managed himself to do what these courtiers had not been able to do for a long time - discredit Birbal in the emperor's eyes!
"I would have been disappointed if this was the choice made even by my lowliest of servants," continued the emperor. "But coming from you it's not only disappointing, but shocking and sad. I did not know you were so debased!"
How did Birbal justify his answer to the enraged and hurt Emperor?
"One asks for what one does not have, Your Majesty." said Birbal, smiling gently and in quiet tones.
"Under Your Majesty´s rule, justice is available to everybody. But I am a spendthrift and always short of money and therefore I said I would choose the gold coin."
The answer immensely pleased the emperor and respect for Birbal was once again restored in the emperor's eyes.