Solved – You randomly select two distinct integers between 1 and 100. What is the probability that the larger number is exactly twice the smaller number

combinatoricsprobability

I recently took a HackerRank test for a Data Science position and got this question wrong. I came to 1/200. Here's how:

There are 50 combinations that will make this true. (i.e. {1,2},{2,4},{3,6}…{50,100}). Probability of a specific number being chosen is 1/100. Probability that the specific set will be chosen is (1/100 * 1/100).

Since there are 50 sets,

P=50*(1/100)*(1/100)=1/200

I'm of course assuming that 1 and 100 are included. But this was the wrong answer. Can anyone help me understand my mistake?

Best Answer

Your first mistake is that there are 50 outcomes, there's actually 100 (Edit: See comment below for clarification). This is because getting (1,2) and (2,1) are the results of two seperate outcomes, but in each case the larger number is exactly twice the smaller number.

So the total possible ways of getting this is actually given by the set:

{ (1,2), (2,1), (2,4), (4,2), ..., (50,100), (100,50) }

Which is a list of 100 possible outcomes.

The total number of possible outcomes is $100 \times 99$

Since there are 100 possible numbers to choose the first time, and then 99 for the second since they must be distinct.

Hence the answer is given by:

$P = \frac{100}{100 \times 99} = \frac{1}{99}$

Using the same argument, it is straightforward to prove that the probability for the more general case of choosing numbers from $1, 2, ..., n$ where $n$ is some positive even number is given by:

$P = \frac{1}{n-1}$