Some 1 and 9s
An exciting question asked in recent quant interview round by Da Vinci in IITB this year
An 8−digit number is going to be created by a two-step process. First, select a uniformly random integer k from {0,1,2,3, … 8 }. Afterwards, we select one 8−digit number uniformly at random from the collection of 8−digit numbers with exactly k 1s and the other 8−k digits are 9s. Call this selected number X. Find E[X]
Try to solve this problem yourself before moving on to the solution below
.
.
.
.
.
.
Solution
Let X_i be the digit in the 10^i spot in X, with X_0 being in the ones spot. For each digit X_i, it is equally likely whether or not it is a 1 or 9. This is because of the fact that we select k uniformly at random, so there as are equally many 8−digit integers with k 1s as k 9s, we can view them as just flipped around. Therefore,
E[X_i]=(1+9)/2=5
We can write
Therefore,
This gives us,
E[X] = 5.(10^7 + … + 10 + 1) = 5 * (11111111) = 55555555
.
.
😃 Over to you: Were you able to solve this?
👉 If you liked this post, don’t forget to leave a like ❤️. It helps more people discover this newsletter on Substack and tells us that you appreciate solving these weekly questions. The button is located towards the bottom of this email.
👉 If you love reading this newsletter, feel free to share it with friends!
Wanted to share another solution, considering the min and max value of X we have:
X_min => when K = 8 then X_min = 11111111
X_max => when K = 0 then X_max = 99999999
as to calculate the expected value we can simply find the average of the 2 extreme values
E[X] = (11111111 + 99999999) / 2 = 55555555
let me know if this helps 😊