• 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

It's a matter of semantics.

There is one room. There are n mathematicians.

We have 2 different groups of mathematicians: the mathematician that is required to be in the room (since each room must have at least one mathematician), and the rest. That one mathematician, can be one of the n mathematicians, while the rest of the mathematicians (the n-1 mathematicians) just hang around.

My formula gives the answer of only 1 way to partition the mathematicians if there is only one room. Test it out and see if it works.
 
Hi IlyaKEightSix,

No mathematician is left out. Each and every one of them will be in some room, but all at the same time. Please take a moment and read the problem one more time.

As I said earlier, this problem involves -- to the best of my understanding -- the Inclusion/Exclusion Principle applied in a most general way.

If someone can come up with a solution that skirts the I/E Principle, I'd like to see it. I suspect it's out there. I'll give it a thought myself.
 
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.

........

Wow. I can't believe how far of the scale I was. It seems so flagrant. I will keep in mind the idea of testing answers in extreme cases.
 
Did I drop a penny?

The answer I got for this problem (assuming I interpret it correctly) is .8. 40 pennies, 8 nickels, 2 dimes. 40/50=.8, unless there is another way of making one dollar with 50 coins.

Edit: This is also under the assumption that you are equally likely to drop any one of the coins as pennies are smaller than nickels but larger than dimes.

You are half way there. Actually there are two cases, which can be computed using the equations:
2 * 10 cents + 2 * 5 cents + 45 * 1 cent + 1 * 25 cents => P[ dropped a penny ] = 45 / 50
40 * 1 cents + 8 * 5 cents + 2 * 10 cents => P[dropped a penny] = 40 / 50(easily verifiable using the equations)
Thus total P[dropped a penny] = (0.9 + 0.8) / 2 = 0.85
 
Partitioning the 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?
Well I did attempt the problem and am arriving at a trivial solution(sure something is wrong but unable to pinpoint)

The number of ways to put ( N )mathematicians into ( K ) rooms is ( K ^ N )
This does not ensure for all rooms being full etc. Now the number of ways to leave exactly the first room empty is ( (K-1) ^ N). Now similarly for the other rooms. This also takes into account that more than 1 room is empty(but atleast one is)
Thus the final answer is ( (K ^ N) - K * ( (K-1) ^ N) )
 
Now, what is the (or a) divisibility test for 7, or for 13, for any prime p?
There is a simple technique I read about long time back. This should help with most divisibility tests(including 7 and 13)
Let ABCDE be the number that we want to check for divisibility by 7,
Now consider ABCDE = 10 ^ 4 * A + 10 ^ 3 * B + 10 ^ 2 * C + 10 * D + E
If (ABCDE % 7 == 0)
=> ((ABCDE + N * 7) % 7 == 0) for all N
=> (ABCDE - 21(or 91 or + 49 )* E * 7) % 7 == 0.
=> Thus ABC(D-2E)0 % 7 == 0
=> (10 *(ABC(D-2E))) % 7 == 0
=> ABC(D-2E) % 7 == 0 //Since 10 and 7 are co prime
Thus we have reduced the number of digits. Similarly with 13 we need to add 3 times the last digit to the remaining number and check for divisibility.
This helps in a lot of cases


It turns out that every prime number has one or more divisibility tests. Can you prove it?

Hmm if you know the proof a small hint would be nice. I have spent quite a bit of time on this already, without any success :(
 
There is a simple technique I read about long time back. This should help with most divisibility tests(including 7 and 13)
Let ABCDE be the number that we want to check for divisibility by 7,
Now consider ABCDE = 10 ^ 4 * A + 10 ^ 3 * B + 10 ^ 2 * C + 10 * D + E
If (ABCDE % 7 == 0)
=> ((ABCDE + N * 7) % 7 == 0) for all N
=> (ABCDE - 21(or 91 or + 49 )* E * 7) % 7 == 0.
=> Thus ABC(D-2E)0 % 7 == 0
=> (10 *(ABC(D-2E))) % 7 == 0
=> ABC(D-2E) % 7 == 0 //Since 10 and 7 are co prime
Thus we have reduced the number of digits. Similarly with 13 we need to add 3 times the last digit to the remaining number and check for divisibility.
This helps in a lot of cases


Hmm if you know the proof a small hint would be nice. I have spent quite a bit of time on this already, without any success :(


There is a theorem known as Fermat's Theorem (which is a special case of Euler's Theorem), which goes like this: If p is prime and p is not a factor of positive integer A, then

A^(p-1) is congruent to 1 modulus p.

That is,

{[A^(p-1)] - 1} % p == 0.

Assume p is different from 2 and 5, as these primes already have divisibility tests.

Now consider an (n+1)-digit number X, written in base 10 as

<a(n),a(n-1),a(n-2), ... ,a(2),a(1),a(0)>.

So, X = sigma{(a(j)*(10^j) as j runs from 0 to n}.

Now, for each j, divide 10^j by p, and note the remainder (10^j)%p.

For each j, {(10^j)%p} == {(10^(p-1+j))%p} [[See the proof below]]

So, the remainders repeat cyclically with a period of p. So, if we denote these p remainders as r(j), where j runs from 0 through n, then the divisibility test goes like this:

<a(n),a(n-1),a(n-2), ... ,a(2),a(1),a(0)> is divisible by prime p if and only if

sigma{(a(j)*r(j) as j runs from 0 to n} is divisible by p.



Note that the number of remainders, which is of course p, is known as soon as p is given.


Proof of Above Claim:

Suppose p is different from 2 and 5. Then, by Fermat, p divides {(10^(p-1) - 1}.

So, p also divides (10^j)*{(10^(p-1)) - 1}=={(10^(p-1+j)) - 10^j}.

There exist integers S and T such that


(10^(p-1+j) ) = S*p + {(10^(p-1+j))%p},

(10^j) = T*p + {(10^j)%p}.


Obviously p must divide the difference between the two above, hence the result. Note that the remainders must be less than p. (Work it in detail and think about it.)
 
You are half way there. Actually there are two cases, which can be computed using the equations:
2 * 10 cents + 2 * 5 cents + 45 * 1 cent + 1 * 25 cents => P[ dropped a penny ] = 45 / 50
40 * 1 cents + 8 * 5 cents + 2 * 10 cents => P[dropped a penny] = 40 / 50(easily verifiable using the equations)
Thus total P[dropped a penny] = (0.9 + 0.8) / 2 = 0.85

Right you are...

My god...so that's like 1 question right (the flea) out of like 5 that I tried, and one that I'm only halfway there on...what exactly should be the ratio of right:attempted on this board to be worth anything professionally?
 
Well I did attempt the problem and am arriving at a trivial solution(sure something is wrong but unable to pinpoint)

The number of ways to put ( N )mathematicians into ( K ) rooms is ( K ^ N )
This does not ensure for all rooms being full etc. Now the number of ways to leave exactly the first room empty is ( (K-1) ^ N). Now similarly for the other rooms. This also takes into account that more than 1 room is empty(but atleast one is)
Thus the final answer is ( (K ^ N) - K * ( (K-1) ^ N) )


It helps a lot if you take a look at other posters' attempts to solve this problem and the discussion surrounding their attempts.

Before submitting a response, take the time to check your soution for special cases, usually extreme values, or endpoint values, or small-numbered and very large-numbered values. If you discover that your answers do not give the correct results for these extreme cases, then you go back and try harder to improve your solution.

Now, to be more specific. I've given a similar response earlier: Suppose k=n. That is, there are n mathematicians and n rooms. In how many ways can these n mathematicians be placed within these n rooms? The correct answer obviously is n!

Does your formula give n!, as the answer?:)
 
May The Calc Be With You!

There is a road in the first quadrant of the xy-coordinate plane whose graph is given by xy=1. Beginning from a point S(s,1/s) on this road, where s is extremely small but positive, your objective is to drive your car to the origin E(0,0). You have the option of driving on the road or off the road. Your constant speed on the road is 1, whereas off the road the constant speed is v, where v<1. In order to minimize the travel time, describe the path driven. Specifically, at what point on the road, do you begin to get off the road so that the total travel time is minimized? Assume turning the car's direction when getting off the road is instantaneous.
 
There is a road in the first quadrant of the xy-coordinate plane whose graph is given by xy=1. Beginning from a point S(s,1/s) on this road, where s is extremely small but positive, your objective is to drive your car to the origin E(0,0). You have the option of driving on the road or off the road. Your constant speed on the road is 1, whereas off the road the constant speed is v, where v<1. In order to minimize the travel time, describe the path driven. Specifically, at what point on the road, do you begin to get off the road so that the total travel time is minimized? Assume turning the car's direction when getting off the road is instantaneous.
I'll use the standard approach of calculating the time and differentiating to find minima. Lets say that individual leaves the road at point T(and then takes a straight path, assumption easily justifiable)
Total Time is
(\int_{s}^{t} \sqrt{1 + \frac{1}{x^4}} dx + \frac{1}{v}\sqrt{t^2 +\frac{1}{t^2}} )
Taking differential wrt t(Leibnitz formula) and equating to 0(for minima)
( t = \large(\frac{1 - v}{1 + v}\right)^{1/4})
This uses the fact that S is extremely small & != 0
 
I'll use the standard approach of calculating the time and differentiating to find minima. Lets say that individual leaves the road at point T(and then takes a straight path, assumption easily justifiable)
Total Time is
(\int_{s}^{t} \sqrt{1 + \frac{1}{x^4}} dx + \frac{1}{v}\sqrt{t^2 +\frac{1}{t^2}} )
Taking differential wrt t(Leibnitz formula) and equating to 0(for minima)
( t = \large(\frac{1 - v}{1 + v}\right)^{1/4})
This uses the fact that S is extremely small & != 0

Hi ramnik,

Crisp and clean! Well done. Thanks.
 
It helps a lot if you take a look at other posters' attempts to solve this problem and the discussion surrounding their attempts.

Before submitting a response, take the time to check your soution for special cases, usually extreme values, or endpoint values, or small-numbered and very large-numbered values. If you discover that your answers do not give the correct results for these extreme cases, then you go back and try harder to improve your solution.

Now, to be more specific. I've given a similar response earlier: Suppose k=n. That is, there are n mathematicians and n rooms. In how many ways can these n mathematicians be placed within these n rooms? The correct answer obviously is n!

Does your formula give n!, as the answer?:)
My apologies. I had a gut feeling that something was wrong but couldn't figure out the exact reason(I should have spent a moment testing my results). The problem arises due to permutations inside a room.
After spending more time on it(and brushing up my P&C), I finally arrived at something.
The solution uses Stirling's number.
Stirling's Number S(n,k): The number of ways to partition a set A {#(A)=n} into k parts.
For case n=k the answer is trivial. Only interesting solution exists for n > k.
If the rooms were indistinguishable then the answer would be S(n,k).(as from the definition of Stirling number)
Since the rooms are distinguishable, we can permute the rooms and thus the answer to the above problem is k!*S(n,k).
For more on Stirlings number read PlanetMath: Stirling numbers of the second kind
Nice question Quantyst. I want more.
 
I do not think your answer is correct. Look at simple case where n=3, k=2. Just enumerate all the possible cases, you will see it should be 6. But your answer is 3. And for n=4,k=2, the answer is 14, but yours is 24.

The answer should be nPk*k!*k^(n-k)/Q(n,k), where Q(n,k) is the recount number. It means first pick k from n and fill the k rooms, since they are both numbered, any permutation needs to be considered. Then we have n-k left, each has k positions to choose. But of course there are some recounts, that is why we divide it by Q(n,k). It seems to me that Q(n,k) has some recursion relationship and Q(n,k)=nPk when n=k.

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?
 
Hey thanks -- yes, please why don't you elaborate a bit!
ps. I mean, ok, you calculate the prob of not dying in d1, then the joint prob of not dying in d2 which is the (1-x)^d2/d1 term and then 1- the term is the prob of dying ...
 
Hey guys,

so, if I have x% chance to die in an auto accident from NYC to Philly (say distance d1) what is the chance that I die in an auto accident from NYC to, say, Oregon (say distance d2)?

rio


Answer: 1-(1-x%)^(d2/d1)


1. Chance of dying in a distance of d1 is x%.

2. Chance of not dying in a distance of d1 is 1-x%.

3. Chance of not dying in per unit of distance is (1-x%)^(1/d1).
This is so because to not die along the entire distance of d1 is to not die (independently) along every one of the unit distances (of which there are d1) comprising the entire distance d1. Obviously multiplying (1-x%)^(1/d1) by itself d1 times (as the events are independent) will give the result (1-x%), the probability of not dying along d1.
4. Chance of not dying along d2 is [(1-x%)^(1/d1)]^d2 = (1-x%)^(d2/d1).

5. Chance of dying along d2 is therefore 1- (1-x%)^(d2/d1).




 
Partitioned 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?



Solution:

This solution is an incomplete one. I will not provide a closed-form formula in terms of n and k. Instead I will come up with a recursive relation. The closed-form formula will be presented in another post.

Let f(n,k) denote the number of ways to place n mathematicians in k rooms such that in each room there will be at least one mathematician.

Now partition the set of all these ways according to the number of mathematicians in room k. So, imagine j mathematicians are placed in room k, where 0<j<n-k. There are C(n,j) ways to choose j mathematicians out of the n that can be placed in room k, where C(n,j)=n!/[j! (n-j)!]. For each choice of j mathematicians placed in room k, the remaining (n-j) mathematicians will be placed in rooms 1 through (k-1) in f(n-j,k-1) ways. So, for each choice of j where 0<j<n-k, there are a total of C(n,j)* f(n-j,k-1) ways in which j mathematicians are placed in room k and (n-j) are placed in rooms 1 through (k-1), with all the rooms non-empty. So, all we have to do now is to sum up all these ways to get the grand total, the answer to the question:

f(n,k)=sigma{ C(n,j)* f(n-j,k-1) as j runs from 1 through n-(k-1)}.

The preceding can be simplified to

f(n,k)=sigma{ C(n,j)* f(j,k-1) as j runs from k-1 through n-1}, which can be written as

f(n,k)=sigma{ C(n,j)* f(j,k-1) as j runs from 0 through n-1}.

Note: f(n,k)=0 and C(n,k)=0 if n<k, where k>0. Some other initial values need to be determined.
 
Solution:
Let f(n,k) denote the number of ways to place n mathematicians in k rooms such that in each room there will be at least one mathematician.
This f(n,k) is the Stirling's number of the second kind and read my post regarding the same for more information(and a solution).
 
Back
Top