• 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

Alternative Solutions to A Problem

Hi. This is a great forum!! The interview questions are very useful. I have a method to solve two of the problems that may have been overlooked.

1. Find x in x^(x^(x^ ... ) = 2

2. Calculate \sqrt{ 2 + \sqrt{2 + \sqrt{2 + \sqrt{2 + ...} }}}


In both of these we can rephrase the problem in terms of convergence of a series.

Solution to problem 1.

Consider the recursive relation: x_{n+1} = x^{x_n}. Then problem 1 can be restated as lim_{n -> infininty} x_n = 2. Assuming convergence (which we can show later), this requires that x_n = x^{x_n} = 2, i.e. 2 = x^2, so that x = \sqrt{2}.


Solution to problem 2. The approach is very similar.

Let x_{n+1} = \sqrt{2 + x_n}, x_0 = 0. Then assuming convergence we have that x_infinity = \sqrt{2 + x_infinity}, so that squaring both sides we get x_infinity^2 = 2 + x_infinity, which has solutions { -1, 2}. Of course, since the square root function is increasing and we start at x_0 = 0, we choose the solution x_infinity = 2.

-N
 
Not sure this can be done. Certainly 3 combinations can be accommodated by just putting condom #1 nested inside condom #2 and then going through the scenarios. But two couples means 4 different combinations, and I can't see how to get the 4th one. Any takers?

-Nick

Here's one that if a quant applicant can't get, you throw them out the door with the closest thing that passes for a catapult.

Two heterosexual couples are determined to have group sex between all sets of male-female couples, and none want to catch any potential STD, but only have two condoms.

In what procedures is this event possible?


A more challenging follow up would be: what is the minimum number of condoms required for N such couples?
 
Here's a collection of XKCD puzzles.

One more probability puzzle

Given a set X with N elements, and sets A and B which are subsets of X, what is the probability of A being a subset of B.
[edit] Coin tosses

(From here)
Sue and Bob take turns rolling a 6-sided die. Once either person rolls a 6 the game is over. Sue rolls first, if she doesn't roll a 6, Bob rolls the die, if he doesn't roll a 6, Sue rolls again. They continue taking turns until one of them rolls a 6.
Bob rolls a 6 before Sue.
What is the probability Bob rolled the 6 on his second turn?
Note: it is not (5/6)*(1/6).
[edit] Ants

100 ants (zero-length points) walk on a meter stick (a line) at 1 cm/second. When two ants collide, they both reverse direction. If an ant reaches the end of the stick, it falls off. What arrangement of ants maximizes the time before all ants have fallen off? How long can they last?
[edit] Blue Eyes Puzzle

A group of people with assorted eye colors live on an island. They are all perfect logicians -- if a conclusion can be logically deduced, they will do it instantly. No one knows the color of their eyes. Every night at midnight, a ferry stops at the island. Any islanders who have figured out the color of their own eyes then leave the island, and the rest stay. Everyone can see everyone else at all times and keeps a count of the number of people they see with each eye color (excluding themselves), but they cannot otherwise communicate. Everyone on the island knows all the rules in this paragraph.
On this island there are 100 blue-eyed people, 100 brown-eyed people, and the Guru (she happens to have green eyes). So any given blue-eyed person can see 100 people with brown eyes and 99 people with blue eyes (and one with green), but that does not tell him his own eye color; as far as he knows the totals could be 101 brown and 99 blue. Or 100 brown, 99 blue, and he could have red eyes.
The Guru is allowed to speak once (let's say at noon), on one day in all their endless years on the island. Standing before the islanders, she says the following:
"I can see someone who has blue eyes."
Who leaves the island, and on what night?
There are no mirrors or reflecting surfaces, nothing dumb. It is not a trick question, and the answer is logical. It doesn't depend on tricky wording or anyone lying or guessing, and it doesn't involve people doing something silly like creating a sign language or doing genetics. The Guru is not making eye contact with anyone in particular; she's simply saying "I count at least one blue-eyed person on this island who isn't me."
Note: The answer is not "no one leaves."
[edit] The Monty Hall Problem

Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat (At this point in the show, he always opens a door to show a goat regardless of what you picked.) He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
Note: It is assumed you would rather win a car over a goat.
Note: Assume h = 6.626 068 96×10^{−34} Js
[edit] Resistor Grid

Given an infinite rectangular lattice of 1-ohm resistors, what is the equivalent resistance between two nodes a knight's-move away?
Note: This one is not so much counterintuitive as just mathematically difficult.
[edit] The Bridge

4 people need to traverse a bridge. The bridge is old and only two persons can use it at the same time. It is night and to traverse the bridge a flashlight is needed.
The group only has one flashlight. Each person traverses the bridge at different speeds and when 2 go together the faster one needs to adapt for the slower one (otherwise they can't share the light).
The first person (A) needs 10 minutes to cross the bridge. The second (B) 5; the third (C) 2 and the fastest one (D) only 1 minute.
How long does it take the group to cross the bridge.
Example (not the most efficient one):
A+D -> // 10 min (let's assume the slowest and the fastest go first)
D <- // 1 min (D needs to bring back the flashlight)
B+D -> // 5 min
D <- // 1 min
C+D -> // 2 min (and the group has crossed the bridge)
--
totals 19 minutes.
There is a better way.
Note: A computer program would find the solution. So no tricks involved.
[edit] Coin tosses 2

Sue and Bob are playing the following game:
Sue pays Bob $2 to start the game. Then Bob starts tossing coins. If the coin falls on head Bob pays Sue $1 and continues tossing the coin. If however the coin falls on tails then the game is finished.
Example 1: Sue pays Bob $2. Bob tosses head three times in a row before finally tossing a tails. For each head Bob pays Sue $1 and Sue thus wins $1.
Example 2: Sue pays Bob $2. Bob starts by tossing tails and Sue thus loses her $2.
Clearly Sue has a disadvantage here. The question is: what is the correct initial amount, so that neither Sue nor Bob have an advantage.
Note 1: the difficulty lies in the fact, that Sue could potentially win an infinite amount of money if there is an infinite number of head-tosses.
Note 2: there is a way to easily get the correct amount without getting into "infinity".
[edit] Smurfs and Gargamel

Gargamel has captured 100 Smurfs. Feeling confident he proposes the following game:
He will exchange the white hats of an undefined number of smurfs with red hats. No smurf knows his own color. All smurfs can see each other, but they have no other means of communication. Then, each Smurf (order selected by Gargamel) should say the color of his hat (loudly so that everyone can hear it). If it is correct, then he lives, otherwise he dies.
After a short discussion the smurfs accept. They know that the first Smurf to be chosen might die, but all 99 other smurfs will survive.
How?
Note: as usual no trick. Nothing time-related...
[edit] Prisoners

100 people are being held prisoner in a jail. They are told that in one hour, they will all be taken to separate windowless, soundproof cells. One at a time, and in a random order, they will be taken from their cells, interrogated, and then sent back to their cells. All interrogations will take place in the same room, which contains one light bulb and the switch that operates it. The light is initially off, but the inmates are free to toggle the switch as often as they want, whenever they are in the interrogation room, and the prison guards will not toggle the switch at all. Only one prisoner is interrogated at a time, each prisoner can be interrogated multiple times, and they have no way of communicating besides the light switch. The length and amount of time between interrogations is random, so no help there.
At any time, any prisoner under interrogation may state, "Everyone has been interrogated at least once." If this statement is true, everyone will be released. If it is false, all of the prisoners will be executed.
The prisoners have one hour to work out their strategy before they're isolated for good. How do they get released?
Note: The selection process for interrogations is random and fair; some prisoners may be interviewed multiple times before another prisoner is interrogated at all, and after any point in time, every prisoner will be interrogated an infinite number of times more.
Note2: For bonus points, what is their strategy if they don't know the initial state of the light switch?
Alternative: suppose there is one interrogation per day. In this case there exist different more efficient solutions.
[edit] Pirates

100 pirates (p1, p2, ... p100) are dividing up a treasure consisting of 50 indivisible gold coins of equal worth. The pirates have a total-order hierarchy, i.e. pirate p1 is the head pirate, p2 is a rank lower in the order, p3 lower still, ... The process works like this: The highest ranking pirate which is still alive proposes how he would like to divide the treasure. Then all living pirates (including him) vote on the proposal. If at least half of the pirates alive vote for the proposal, then it is accepted, otherwise the pirate who made the proposal is killed and the process is repeated. The pirates are perfectly intelligent, logical and rational (see Blue Eyed Puzzle). Each pirate's priorities are, in this order: Survival, wealth (getting the highest number of coins possible), bloodthirstiness (seeing as many pirates killed as possible, other than himself). In other words a pirate will always choose an outcome in which he lives over one in which he dies. Given two outcomes in which he lives, he will choose the one where he gets more coins. And given two outcomes in which he lives and gets the same number of coins he will choose the one in which the highest number of other pirates die. How will the gold coins be divided?
Note: For bonus points, how will the gold coins be divided if there are 200 pirates?
[edit] Cyclic List Algorithms

Not really "puzzles" per se, but still very interesting.
Find an algorithm that determines if a list is cyclic. The algorithm should be in O(n) for speed (where 'n' is the number of distinct elements of the list) and in O(1) for space.
The list does not necessarily start with a cycle.
For Schemers, the following would be a cyclic list:
(let ((l (list 1 2 3)))
(set-cdr! (cddr l) (cdr l)))
Once that's done: if the list is cyclic find (same complexities) the first element that is within the cycle. In the example above that would be 2 of the sub-list '(2 3 ...).


[edit] Two Beagles

A shopkeeper says she has two new baby beagles to show you, but she doesn't know whether they're male, female, or a pair.
You tell her that you want only a male, and she telephones the fellow who's giving them a bath.
"Is at least one a male?" she asks him. "Yes!" she informs you with a smile.

What is the probability that the other one is a male?
(The birth ratio of beagles is exactly 50/50 for the purpose of this problem)
[edit] String-burning

You have 2 pieces of string of different, unspecified length, and some matches. Each piece of string takes one hour to burn, but the burn rate is not constant. This means that it could take 59 minutes to burn the first 1/4, and 1 minute for the rest. The strings have different burn rates, and of course you don't know the rates anyway.
Using only the matches and the strings, measure 45 minutes.
[edit] Magic Watch

You have a very nice, shiny watch. But this is no ordinary watch. This watch can answer two yes or no questions 100% accurately per day. You ask, and either a blue or yellow light will flash. Unfortunately, you don't know which light means yes and which light means no, and you can never find out because there's a 50-50 chance of the lights switching every night.
You happen to be on a game show. The rules are simple. There are three doors. Behind two are goats. Behind one is a shiny red car. Obviously, you want the car. You can choose any door, after asking the watch two questions.
What are the two yes/no questions you can ask so that you will have a 100% guaranteed chance of getting the car?
[edit] Light Bulbs

There are 100 light bulbs lined up in a row in a long room. Each bulb has its own switch and is currently switched off. The room has an entry door and an exit door. There are 100 people lined up outside the entry door. Each bulb is numbered consecutively from 1 to 100. So is each person.
Person No. 1 enters the room, switches on every bulb, and exits. Person No. 2 enters and flips the switch on every second bulb (turning off bulbs 2, 4, 6, ...). Person No. 3 enters and flips the switch on every third bulb (changing the state on bulbs 3, 6, 9, ...). This continues until all 100 people have passed through the room.
How many of the light bulbs are illuminated after the 100th person has passed through the room? More specifically, which light bulbs are still illuminated, and why?
[edit] Dumbass, M.D.

From defective yeti: Dumbass, M.D.
You have Some Terminal Condition, which necessitates taking two pills a day: one Pill A and one Pill B. If you neglect to take either pill, you die; if you take more than one A or more than one B, you die. If you don't take them at exactly the same time, you die.
This morning you are going through your usual routine. You pick up your bottle of A Pills and gently tap one into your palm. Then you pick up your bottle of B Pills and tap it, but two pills accidentally fall into your hand. You now hold three pills (one A and two Bs), you don't know which are which, and they are completely indistinguishable from each other. The A Pills are the same color as the B Pills, they are the same shape, same size -- they are identical in every respect. Man, your doctor is a dumbass. But he's a rich dumbass, because he's charging you $10,000,000 a pill! So you dare not throw any away.
Thus, the puzzle: what can you do to ensure that you take only one A Pill and only one B Pill today, without wasting any pills (either today or in the future)?
[edit] PEARLS!

Yragle the pirate has 100 white pearls and 100 black pearls. The white pearls are worthless, the black pearls are priceless. He will let you arrange the pearls in two sacks, and then after he mixes up the pearls in each bag and shuffles the bags he will let you pick a pearl from one of the two bags. How should you distribute the pearls between the two sacks to maximize your odds of getting a black pearl?
[edit] Bit Algorithm

Apparently the following algorithmic problem has been given during Google interviews.
Propose an algorithm that counts the number of bits that are 1 in a given number n.
Your algorithm should not rely on any assumptions on the number's size (nb of bits) and should be in O(i) where i is the number of 1-bits inside n. We assume that operations (bit-operations and arithmetic operations) can be executed in constant time.
[edit] One-lane Highway

(Another interview question)
You have N cars that are all traveling the same direction on an infinitely long one-lane highway. Unfortunately, they are all going different speeds, and cannot pass each other. Eventually the cars will clump up in one or more traffic jams.
In terms of N, what is the expected number of clumps of cars?
 
ue and Bob take turns rolling a 6-sided die. Once either person rolls a 6 the game is over. Sue rolls first, if she doesn't roll a 6, Bob rolls the die, if he doesn't roll a 6, Sue rolls again. They continue taking turns until one of them rolls a 6.
Bob rolls a 6 before Sue.
What is the probability Bob rolled the 6 on his second turn?

(5/6*5/6*5/6*1/6)/(5/6*1/6+5/6*5/6*5/6*1/6+ infinite series)
=Probability of Bob winning in second turn/Probability of Bob winning
=25/144

For the ants I can only come up with the idea of uniformly distributing 100 ants all through the stick and pitting pairs of them in opposite directions.
 
Quote:
One more probability puzzle
Given a set X with N elements, and sets A and B which are subsets of X, what is the probability of A being a subset of B.


Ans: (3/4)^N.
 
Quote:
Ants
100 ants (zero-length points) walk on a meter stick (a line) at 1 cm/second. When two ants collide, they both reverse direction. If an ant reaches the end of the stick, it falls off. What arrangement of ants maximizes the time before all ants have fallen off? How long can they last?


Hint: Given that when two ants collide, they reverse direction with the same speed as before (1 cm/sec), it is as if the ants pass through each other without colliding! Think of the ants as being interchangeable.
 
Quote:
The Monty Hall Problem
Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat (At this point in the show, he always opens a door to show a goat regardless of what you picked.) He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?
Note: It is assumed you would rather win a car over a goat.

Suggestion:

1. Generalize this problem to N doors, with exactly one car behind one of the doors and with (N-1) goats behind the other doors.

2. Generalize this problem to N doors, with exactly K cars behind K of the doors (i.e., a car behind each of K doors, for a total of K cars) and with (N-K) goats behind the other doors (i.e., a goat behind each of the other (N-K) doors, for a total of (N-K) goats). You may assume K<N.
 
Quote:
One-lane Highway
(Another interview question)
You have N cars that are all traveling the same direction on an infinitely long one-lane highway. Unfortunately, they are all going different speeds, and cannot pass each other. Eventually the cars will clump up in one or more traffic jams.
In terms of N, what is the expected number of clumps of cars?


Observation:

There is more than meets the eye upon first reading of this problem. A factor that needs to be considered is the initial distance of separation between consecutive cars. For example, suppose N=4, with the cars moving in W-E direction and numbered in the same direction as A,B,C,D and having the speeds 4,3,2,1, respectively. If the initial distance between cars A and B is much smaller than the initial distance between cars B and C, then of course there will be two clumps, whereas if the initial distance between A and B is much greater than the distance between B and C, and D is way ahead of all the cars, then there will be only one clump.
 
Quote:
One more probability puzzle
Given a set X with N elements, and sets A and B which are subsets of X, what is the probability of A being a subset of B.


Ans: (3/4)^N.


Shouldn't this be (3/4)^(N-1), as when there is one element, that A is a subset of B already?

How did you arrive at 3/4, also?
 
Quote:
One-lane Highway
(Another interview question)
You have N cars that are all traveling the same direction on an infinitely long one-lane highway. Unfortunately, they are all going different speeds, and cannot pass each other. Eventually the cars will clump up in one or more traffic jams.
In terms of N, what is the expected number of clumps of cars?


Observation:

There is more than meets the eye upon first reading of this problem. A factor that needs to be considered is the initial distance of separation between consecutive cars. For example, suppose N=4, with the cars moving in W-E direction and numbered in the same direction as A,B,C,D and having the speeds 4,3,2,1, respectively. If the initial distance between cars A and B is much smaller than the initial distance between cars B and C, then of course there will be two clumps, whereas if the initial distance between A and B is much greater than the distance between B and C, and D is way ahead of all the cars, then there will be only one clump.
No initial separation will not matter thats what infinite length of road is given for. I think a recursive c program would do good to find its answer ?
 
ue and Bob take turns rolling a 6-sided die. Once either person rolls a 6 the game is over. Sue rolls first, if she doesn't roll a 6, Bob rolls the die, if he doesn't roll a 6, Sue rolls again. They continue taking turns until one of them rolls a 6.
Bob rolls a 6 before Sue.
What is the probability Bob rolled the 6 on his second turn?

(5/6*5/6*5/6*1/6)/(5/6*1/6+5/6*5/6*5/6*1/6+ infinite series)
=Probability of Bob winning in second turn/Probability of Bob winning
=25/144
answer should be 5/36
 
No initial separation will not matter thats what infinite length of road is given for. I think a recursive c program would do good to find its answer ?

It is not clear what you mean.

Do you mean that the answer to the problem will be the same whether or not we consider the initial distances between the cars? If so, then we need to prove that. Furthermore, do you see what my example for the case N=4 tries to show? It shows that we need to consider the effect of the initial distances between the cars whether or not the road is infinitely long.

Or, do you mean something else by your comment quoted above?
 
Shouldn't this be (3/4)^(N-1), as when there is one element, that A is a subset of B already?

How did you arrive at 3/4, also?

The answer stands as given. For the case N=0, X={ }, the empty set, and with probability 1, A=B=X, which agrees with (3/4)^N=(3/4)^0=1. Now let N=1. So, X={x}. Then B={ } with prob 1/2 or B=X with prob 1/2. In case B={ }, then A is subset of B with prob 1/2 as A can only be the empty set if it is to be a subset of B. In case B=X, then A is a subset of B=X with prob 1. So, when N=1 and X={x}, then A is a subset of B with prob=(1/2)(1/2)+(1/2)(1)=3/4, which result agrees with (3/4)^N=(3/4)^1=3/4.

So, when there is exactly one element in X, it is NOT true that "A is a subset of B already".
 
It is not clear what you mean.

Do you mean that the answer to the problem will be the same whether or not we consider the initial distances between the cars? If so, then we need to prove that. Furthermore, do you see what my example for the case N=4 tries to show? It shows that we need to consider the effect of the initial distances between the cars whether or not the road is infinitely long.

Or, do you mean something else by your comment quoted above?
Yes you understood me correctly. See if there is a car X with a higher speed behind another car Y than evetually the car X will reach car Y and they they will move together. So only the order of cars on the road will matter and distance wont matter.
P.S. here are some sample answers
for n =1 expected no. of clusters = 1
n =2 expected clusters = 1.5
n =3 expected clusters = 5.5/3
n =4 expected clusters = 26.5/12
 
From the get-go, I was under the misconception that the word "clump" meant that when a faster car reaches a slower car, then both come to a stop and no longer continue to move forward. If the cars came to a stop, then of course initial distances do matter. This conception in fact gives rise to an interesting problem.

But now that you have clarified the situation -- the clumps continue to move forward only at the speed of the front car that has the slowest speed in the clump -- I do agree with you that the initial distances between the cars have no effect on the answers. Thanks.
 
ue and Bob take turns rolling a 6-sided die. Once either person rolls a 6 the game is over. Sue rolls first, if she doesn't roll a 6, Bob rolls the die, if he doesn't roll a 6, Sue rolls again. They continue taking turns until one of them rolls a 6.
Bob rolls a 6 before Sue.
What is the probability Bob rolled the 6 on his second turn?

(5/6*5/6*5/6*1/6)/(5/6*1/6+5/6*5/6*5/6*1/6+ infinite series)
=Probability of Bob winning in second turn/Probability of Bob winning

I agree up to here, since this is equal to P[X=4 | X is even], where X is the first roll resulting in 6 (where the probability space is all sequences dice rolls).

But I think your arithmetic is wrong. It should be (25 * 11) / 6^4.
 
Thanks a lot!

What does XKCD stand for?

As far as I know, XKCD isn't really an acronym. I think it's something the founder of xkcd.com, Randall Munroe, made up.
 
I agree up to here, since this is equal to P[X=4 | X is even], where X is the first roll resulting in 6 (where the probability space is all sequences dice rolls).

But I think your arithmetic is wrong. It should be (25 * 11) / 6^4.

I think the problem can be restated as a Bernoulli experiment where the only thing that matters is that Bob tosses a 6 on the third or fourth trial. That Sue and Bob take turns does not matter. What matter is to account for the fact that Bob is either the first to start the experiment or second (hence success on the third or fourth toss, resp). P(Success) = 1/6. An appropriate distribution for this problem would be the geometric one, hence,

P(Bob wins on second turn) = (5/6)^2 * 1/6 + (5/6)^3*1/6
 
Back
Top