• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Quantitative Interview questions and answers

Die...Oh...Rama!

Keep rolling an n-sided fair die until you get a number that is less than or equal to a previously rolled number, at which point in time the game ends. On average, how many times do you roll before the game ends? What happens as n gets unboundedly large?
 
Keep rolling an n-sided fair die until you get a number that is less than or equal to a previously rolled number, at which point in time the game ends. On average, how many times do you roll before the game ends? What happens as n gets unboundedly large?


Is the answer (3n+1)/(n+1) ?
This will give a limit of 3 as n->infinity.

Here's how I got it.

1. The expected value of making it in 2 turns :-
there are n*n possible outcomes with 2 turns.

If we roll 1 in the first turn then there is 1 chance to end the game on the second turn
If we roll 2 in the first turn then there are 2 chances to end the game on the second turn
If we roll 3 in the first turn then there are 3 chances to end the game on the second turn
... and so on.
Hence total no. of ways in two turns is 1+2+3..n = n(n+1)/2
The probability = n(n+1)/2 divided by n*n = (n+1)/2n

Hence expected value of making it in two turns = 2*(n+1)/2n

2. The expected value of making it in 3 turns :-
The probability of ending the game in any two successive turns is (n+1)/2n as shown above
The probability of not ending the game in any two successive turns is 1- (n+1)/2n = (n-1)/2n

Hence expected value of making it in three turns = 3 * (n-1)/2n * (n+1)/2n

//rly the expected value of making it in 4 turns = 4 * (n-1)/2n * (n-1)/2n * (n+1)/2n

We no get a general term = i * { (n-1)/2n }^(i-2) * (n+1)/2n
We have to sum this from i=2 to infinity to get the expected value of the answer

If we take the (n+1)/2n term out of the summation because it does not contain i term, we get an arithmetico-geometric sequence whose sum is
2*[(n-1)/2n ]^0 + 3*[(n-1)/2n ]^1 + 4*[(n-1)/2n ]^2 +....

taking this sum and multiplying by the (n+1)/2n term taken outside we get the answer
(3n+1)/(n+1)
 
Alas! my answer is wrong. The probability of not ending the game in two successive turns which I have calculated to be (n-1)/2n is incorrect.
 
Hi http://www.quantnet.com/forum/member.php?u=1968Prateek Bhatia,

I am having difficulty understanding a phrase you used.

What do you mean by the following phrase, as you used it just recently:

" Hence expected value of making it in two turns = 2*(n+1)/2n"?

What does " ... expected value ... in two turns ... " mean?

Thanks.
 
Partition These Mathematicians!

There are n mathematicians numbered 1 through n, who want to be placed in k rooms numbered 1 through k, such that in each room, there will be at least one mathematician. In how many ways can you do this?
 
There are n mathematicians numbered 1 through n, who want to be placed in k rooms numbered 1 through k, such that in each room, there will be at least one mathematician. In how many ways can you do this?

Well, assuming n=k, there is exactly n! (or k!) ways to do this (any one of the mathematicians in room 1, any one of the n-1 mathematicians in room 2, and so on...)
Assuming n<k, there isn't a single way to do this.
Assuming n>k, then:

Assuming that each mathematician and room are distinct, then there are nPk ways to arrange the first k mathematicians. Since the rest of the n-k mathematicians can be arranged in any way, I am guessing that this expression is (n-k)^k. So our answer is:

If n=k, n! ways.
If n<k, 0 ways.
If n>k, nPk*(n-k)^k

Am I correct?
 
Keep rolling an n-sided fair die until you get a number that is less than or equal to a previously rolled number, at which point in time the game ends. On average, how many times do you roll before the game ends? What happens as n gets unboundedly large?

I think Prateek is on to something...however...if I knew how to change the seed for a random number generator in C++, I'd monte carlo this problem.

For now, I think that as the die approaches an infinite amount of sides that the number of games needed to end the game approach 2.

It is intuitive, but the problems with the most intuitive answers are often the ones that are hardest to show your reasoning for.
 
Hi

I am a new quantnetter, it is great to see such a community of intellects here...I may be acting foolish...though just wanted to check..these questions are relevant to Job interview or are relevant to your admission to MFE program..

Thanks
 
Well, assuming n=k, there is exactly n! (or k!) ways to do this (any one of the mathematicians in room 1, any one of the n-1 mathematicians in room 2, and so on...)
Assuming n<k, there isn't a single way to do this.
Assuming n>k, then:

Assuming that each mathematician and room are distinct, then there are nPk ways to arrange the first k mathematicians. Since the rest of the n-k mathematicians can be arranged in any way, I am guessing that this expression is (n-k)^k. So our answer is:

If n=k, n! ways.
If n<k, 0 ways.
If n>k, nPk*(n-k)^k

Am I correct?

Hi IlyaKEightSix,

I think you are over-counting! We know that when k=1, the answer to the question is just 1. You have one room to be filled with n mathematicians. That can be done in only one way. But your answer, namely "nPk*(n-k)^k", gives the result n(n-1), which is obviously incorrect. Yes, your method over-counts. My answer involves a summation, which I have no idea how I can simplify further. I'll let you know what my answer is, later!
 
I think Prateek is on to something...however...if I knew how to change the seed for a random number generator in C++, I'd monte carlo this problem.

For now, I think that as the die approaches an infinite amount of sides that the number of games needed to end the game approach 2.

It is intuitive, but the problems with the most intuitive answers are often the ones that are hardest to show your reasoning for.

Did you notice Prateek's later post indicating his answer is wrong? In fact, it is.

Here's the correct answer:

(1+1/n)^n. So as n ---> infinity, the answer becomes e. Cheers!
 
Hi

I am a new quantnetter, it is great to see such a community of intellects here...I may be acting foolish...though just wanted to check..these questions are relevant to Job interview or are relevant to your admission to MFE program..

Thanks

Good question! And fairly difficult to answer given the vagueness of the word "relevant" in your question. Certainly, this forum provides the participants an opportunity to bang heads with like-minded people, i.e., other quants or wannabes. In this way, it is helpful. Quite a few of the questions, even if not the majority, are the sort of things you need to know vis-a-vis an MFE program, and many others afford an opportunity to sharpen the kinds of math skills that might be tested in an interview. As for me, in addition to the foregoing, I just like the fun of it, and enjoy banging my head with others'. It's fun! Cheers!
 
Hi Prateek Bhatia,

I am having difficulty understanding a phrase you used.

What do you mean by the following phrase, as you used it just recently:

" Hence expected value of making it in two turns = 2*(n+1)/2n"?

What does " ... expected value ... in two turns ... " mean?

Thanks.


I meant expectation of 2 turns(i.e game ending in 2 turns) . I tried to add the expectation of each possible 2,3,4.. turns to get the the expected no. of turns it would take to finish the game.
 
Keep rolling an n-sided fair die until you get a number that is less than or equal to a previously rolled number, at which point in time the game ends. On average, how many times do you roll before the game ends? What happens as n gets unboundedly large?

Solution:

It's easier to do this problem by generalizing it a bit. We are given an n-sided fair die, where n is, of course, a natural number. Now let k be an integer in the set {0, 1, 2, ..., n}. Let us generalize by saying that the game ends on the first roll if the rolled number is less than or equal to k. Thereafter, if the game does not end on the first roll, then the game ends upon rolling a number that is less than or equal to a previously rolled number.

Let E(k,n) denote the expectation of the number of rolls before the game ends. We are, of course, particularly interested in finding E(0,n).

We roll at least once. Suppose number j comes up. If j is in the set {1, 2, ..., k} , then the game ends. This happens with a probability of k/n. If j is in the set {k+1, K+2, ..., n}, then the game continues. The probability of j being any one of the numbers in the set {k+1, K+2, ..., n} is 1/n.

Imagine j is one of the numbers in the set {k+1, K+2, ..., n}. Before you roll again, you ask yourself "starting from this point in time, on average, how many times do I roll before the game ends?"

Well, the answer is E(j,n). This is so because if the new about-to-be-rolled number is less than or equal to j, then the game ends, otherwise it continues.

So, we can now express E(k,n) in terms of E(j,n)'s. Here's how:

E(k,n) = 1 + (k/n)*[The first roll j<=k] + sigma{[(1/n)*E(j,n)] as j runs from k+1 through n}.

Of course [The first roll j<=k] tells us that in this event, there is no more rolls as the game has already ended. So,

(*1): E(k,n) = 1 + (1/n)*sigma{[E(j,n)] as j runs from k+1 through n}.

So,

(*2): sigma{[E(j,n)] as j runs from k+1 through n} = n*E(k,n) - n.

The preceding sum begins with j=k+1. So, writing a new sum in which j begins with k+2, we get:

(*3): sigma{[E(j,n)] as j runs from k+2 through n} = n*E(k+1,n) - n.

Now we will 'break up' (*1):

E(k,n) = 1 + (1/n)*(E(k+1,n) + sigma{[E(j,n)] as j runs from k+2 through n}), which in conjunction with (*3) becomes:

E(k,n) = 1 + (1/n)*( E(k+1,n) + (n*E(k+1,n) - n)), which, when simplified, becomes:`

E(k,n) = ((n+1)/n)*E(k+1,n).

O,r equivalently,

(4*): E(k,n) = (n/(n+1))*E(k-1,n).

Iterating (4*), gives us:

(5*): E(k,n) = {(n/(n+1))^k}*E(0,n).

Now, recall that k can be any number in the set {0, 1, 2, ..., n}. So, for k=n, we do know already that E(n,n) =1. So, for k=n, (5*) gives us:

1 = E(n,n) ={(n/(n+1))^n}*E(0,n). From which we get

E(0,n) = (1+1/n)^n.

The rest is history! Cheers!
 
Quantyst, I have to ask you: what is your profession? Are you a quant, or a mathematics professor? Because as a student that has taken every single undergraduate probability course at Lehigh University, that solution was completely out of this world for me. How old are you and what is your background? Because it seems to me that it's a miracle for me, not even 22 yet, to get even one of these questions correct the first try.

Does this mean I'm not quant material, or that I simply have some more to learn/experience?
 
Quantyst, I have to ask you: what is your profession? Are you a quant, or a mathematics professor? Because as a student that has taken every single undergraduate probability course at Lehigh University, that solution was completely out of this world for me. How old are you and what is your background? Because it seems to me that it's a miracle for me, not even 22 yet, to get even one of these questions correct the first try.

Does this mean I'm not quant material, or that I simply have some more to learn/experience?

Hi IlyaKEightSix,

First let me answer your last question above: Quite to the contrary! You certainly are or can be a quant material! You probably have a better chance of getting a legit quant job than I. To be a successful quant, you need to have at your disposal a sufficient amount of relevant knowledge (mostly mathematical) and a battery of rather advanced and useful skills, plus an unflinching go-getter attitude. And young age also helps!

About the solution: I am not sure exactly which one you are talking about. But I will assume you mean the latest which is about the n-sided fair die. Well, you say you are an undergrad student. The approach I've taken in that solution is a common fair in graduate Stochastic Processes courses. You may want to study the following excellent book:

Stochastic Processes (2-nd Edition)

By Sheldon Ross

ISBN 0471120626



I heard the third edition is out. The second one will do just as well.

It is perfectly alright to not be able to get SOMEONE ELSE'S question right, and never be too impressed because they might have had a long time to answer their own questions. I made that question on my own. I do such things every now and then and I enjoy the challenge of solving them, if I can. In this case I was lucky and did manage to solve it. There is another way to solve it, though, by first figuring out the probabilities.

I participate in this forum because doing so is fun. I bang my heads with intelligent and like-minded heads who do not shy away from mathematical challenges. Age should never be a barrier -- but eventually it is.

Oh, how I wish to have your age! I'd spend a million dollars (if I had it) to become as young as you. I am much older than you, but absolutely resolute on getting a quant job. I've been searching for one, but to no avail. Unfortunately, my coding skills (e.g., C++), need a lot of improvement, and because of this I have not been able to land a decent quant job yet.

I have two graduate degrees, both masters, one in Mathematics, the other in Mathematical Finance, basically same as Quantitative Finance. So, I've been doing math for a much longer time than you. Not to worry, YOU WILL CATCH UP AND SURPASS! Good Luck To You!
 
Oh...I once used Introduction to Probability by Grinstead and Snell, although the random processes courses in my university have moved to the above book. Both of them (one is in the IE department, one is in the math...I took the math one). And as for C++...yeah, I should get a move on with that...
 
There are n mathematicians numbered 1 through n, who want to be placed in k rooms numbered 1 through k, such that in each room, there will be at least one mathematician. In how many ways can you do this?

I will attempt this one also. Lets see if its correct.

The answer I get is n! *[ kC(n%k)] where % is the mod-remainder function.

Here's how I got it.

Let us always assume n>=k .

Let q=(n-n%k)/k [ it is the greatest integer such that q < n/k e.g if n=16,k=3 then q=5

Assuming that each mathematician and room are distinct, then there are nPk ways to arrange the first k mathematicians.
Then there are (n-k) mathematicians left. We can arrange them in k rooms in (n-k)Pk ways.
Then there are (n-2k) mathematicians left. We can arrange them in k rooms in (n-2k)Pk ways.
.. and so on till (n-i.k) > k. We know that (n-qk)< k and so (n-(q-1)k) > k . So max value of i will be (q-1)


We will get the product
= nPk * (n-k)Pk * (n-2k)Pk ... (n-(q-1)k)Pk

nPk = n * n-1 * n-2 ......* n-k+1
(n-k)Pk = n-k * n-k-1 * n-k-2 .......*n-2k+1
(n-2k)Pk = n-2k * n-2k-1 * n-2k-2 .......*n-3k+1
(n-(q-1)k)Pk = n-(q-1)k * n-(q-1)k-1 * n-(q-1)k-2 .............* n-qk+1


Therefore the above product is = n * n-1 * n-2 * n-3 ..............* n-qk + 1

= n P qk

( This is because n * n-1 * n-2 ......* n-z+1 = n!/(n-z)! = n P z )

= n P qk

= n P (n - n%k) .....eliminating q


We have placed qk mathematicians. We still have n-qk or n%k mathematicians left. we know that n%k < k. So now we have to place less than k mathematicians in k rooms. This can be done in kP(n%k) ways.


so the final product is [ nP(n - n%k ) ]* [ kP(n%k) ]

Simplifying this further = n!/ (n-n+n%k)! * k!/(k-n%k)!

= n!/(n%k)! * k!/(k-n%k)!

= n! * {k!/[ (n%k)! * (k- (n%k)!)]}

= n! * kC(n%k)

Even if k divides n the solution will work.In that case it will give answer n! which is intuitively correct.

Let me know if I am wrong.
 
Prateek Bhatia wrote:

____________________________________
Assuming that each mathematician and room are distinct, then there are nPk ways to arrange the first k mathematicians.
Then there are (n-k) mathematicians left. We can arrange them in k rooms in (n-k)Pk ways.
Then there are (n-2k) mathematicians left. We can arrange them in k rooms in (n-2k)Pk ways.
.. and so on till (n-i.k) > k. We know that (n-qk)< k and so (n-(q-1)k) > k . So max value of i will be (q-1)
____________________________________


Let M denote the word 'mathematician'.

This is where you begin to over-count. Imagine in the first placement attempt you assign Ms 1 through k respectively in rooms 1 through k, followed by assigning Ms (k+1) through 2k respectively in rooms 1 through k, followed by a certain assignment -- referred to, say, as assignment A -- of the remaining Ms. Call this Placement X.

Now, imagine in the second placement attempt you assign Ms (k+1) through 2k respectively in rooms 1 through k, followed by assigning Ms 1 through k respectively in rooms 1 through k, followed by the assignment A. Call this Placement Y.

Clearly X and Y are identical placements. Yet your method counts them as different.

You also wrote the following formula as your answer:

n! * kC(n%k)

Let's test it. If you have only one room (k=1), then we know there's only one way the Ms can be placed in one room. So, the answer is 1. But your formula gives the answer n!. It over-counts.

I had used the case k=1 to show your earlier formula in an earlier post as incorrect. It took me quite some time to develop an almost instinctual habit of checking my answers with a handful of small-numbered and extreme-numbered cases. But my habit sometimes takes a leave of absence. It's funny ..., we get involved in a protracted messy line of thinking, and often go astray, come up with a solution, and forget to check if our results make sense at all. I still do that every now and then. Then, I decide I have to go back to the drawing board. O.k., square 1.

HINT: Whenever a method over-counts, simply try to remove from it (i.e., subtract) every instance of over-counting. A major idea in combinatorics that is highly useful and versatile is the Principle of Inclusion/Exclusion, in its most general form. In fact I used this principle to do the problem. I will show you the solution some time soon. Read my earlier comments about this in an earlier post.
 
I know of the principle--it appears always in venn diagrams--but answers involving that usually are very heavy-handed. I think there is a very elegant formula here...

Hmmm...let's try this again...to the point where n>k...

First of all, assuming each mathematician and room is distinct, you can arrange the first n mathematicians in the k rooms in nPk ways. If there is one room only, then that *required* mathematician can be chosen in one of n ways.

Now, the amount of mathematicians in any one room is a combination. So once again, assuming we have that one room, then there are n-1 mathematicians left over, but one room. So I think the answer is, taking into account that one room situation as a base:

nPkC(((n-k)Ck)+1)

I think this works out. Going back to n mathematicians in one room, we can arrange that required mathematician in one of nP1=n ways. Now the rest of the mathematicians are arranged in n-1C1=n-1 ways, and then we add 1 because we require a mathematician in every room, and that eliminates the overcounting that if mathematicians A and B are in a room, that if A is required, the situation is different than if B is required.
 
First of all, assuming each mathematician and room is distinct, you can arrange the first n mathematicians in the k rooms in nPk ways. If there is one room only, then that *required* mathematician can be chosen in one of n ways.

Hi IlyaKEightSix,

It seems you've misunderstood the problem. Your first paragraph above reveals your misunderstanding. If there is only one room, then there is only one way in which all n mathematicians can be placed in the set of rooms.
 
Back
Top