# Best riddles

## Anagram Checker

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) A.initializeValues(0) for each character in S1 arrayIndex = mapCharacterToNumber(character) //maps "a" to 0, "b" to 1, "c" to 2, etc... A[arrayIndex] += 1 end for each character in S2 arrayIndex = mapCharacterToNumber(character) A[arrayIndex] -= 1 end for (i = 0; i < 26; i++) if A[i] != 0 return false end end return true end
81.65 %

## Ant and Triangle Problem

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
81.65 %

## I spell the same when you read me forwards as well as backwards

I am a vehicle. I spell the same when you read me forwards as well as backwards. What Am I?
Race car.
81.60 %
funny

Which part of a road do Ghost's love to travel the most?
81.60 %

## It is red but smells like a blue

What is red but it smells like a blue paint?
Red paint.
81.57 %
funny

## Banan go to the doctor

Why did the banana go to the doctor?
Because it was not peeling well.
81.57 %
funny

## The astronauts cavity

What do the dentists call the astronauts cavity?
A black hole.
81.57 %
funny

## Santa

Why is Santa so good at Karate?
Because he has a black belt.
81.57 %

## Workers strike

This is a newspaper headline: Workers Strike - Want to Make Less Money! What is going on?
The workers work at the mint and are tired of being overworked. They want to work less, which is making less money, since money is made at the mind!
81.57 %