• 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

Reach The Summit!

Because it's there, you've decided to climb Mt. Conicus, which is a perfect right circular cone of (vertical) height of H meters and (horizontal) base radius of R meters (where H > R). Since you can rise at most 1 vertical meter for each L meters of movement along the surface of Conicus (where L is much greater than 1 meter), you've decided to go round and round Conicus until you reach the summit. So, you start your trek at the foot of Conicus, but some questions linger in your head:

1.How many meters do I trek before reaching the summit?

2.How many times do I go round Conicus before reaching the summit?
 
Conicus Challenges On...

Right before the embarkation, you begin to worry with a new nagging question:

3. Assuming that Conicus is situated in the xyz-coordinate space such that the summit is at point (0,0,H), the circular base is contained in the xy-plane with center at (0,0,0), and that the trek starts counterclockwise at point (R,0,0), and that the rate of movement on the surface of Conicus is 1 meter/sec, ..., assuming all this, where will I be at any point t in time?
 
A Bug's Life: It's a Crawl!

Two puzzles: the first one you've probably heard a variant of, the second one is a variation on the first.

1. A bug, beginning from the bottom of a 10 meter hole, crawls up at the rate of one meter per hour, but every time the bug climbs two meters, it falls back one meter. How long does it take the bug to get itself to the edge of the hole opening?

2. A bug, beginning from the bottom of a 10 meter hole, crawls up at the rate of one meter per hour, but at the strike of every hour the bug falls back one-tenth of its total displacement from the bottom. How long does it take the bug to get itself to the edge of the hole opening?
 
Two puzzles: the first one you've probably heard a variant of, the second one is a variation on the first.

1. A bug, beginning from the bottom of a 10 meter hole, crawls up at the rate of one meter per hour, but every time the bug climbs two meters, it falls back one meter. How long does it take the bug to get itself to the edge of the hole opening?

2. A bug, beginning from the bottom of a 10 meter hole, crawls up at the rate of one meter per hour, but at the strike of every hour the bug falls back one-tenth of its total displacement from the bottom. How long does it take the bug to get itself to the edge of the hole opening?

1) In the first case, every two hours, the bug climbs one meter every two hours, except for when it reaches the eighth meter, after that it will climb to the edge and crawl out and therefore not fall back. So it'd be 8*2+2=18 hours.

2) As for the second one, I wrote an algorithm for that and after tweaking it, I believe the answer is that the bug never quite reaches the edge of the hole. It gets infinitesimally closer for an infinitely long time, but never reaches the ten meters. Poor critter.

Here's my source code (complete with print statements for debugging...) (On that note, I have to get used to compile/running every so often rather than writing everything and then running it...I'm a bit spoiled by scripting...sorry):

[high]
#include <iostream>

using namespace std;

int main(){
cout<<"Hello World!\n";
double dist;
double time;
cout<<"Dist and time declared!\n";
dist=1;
time=0;
cout<<"Dist and time initialized!\n";
while(dist<10){
cout<<"The loop is now running. \n";
dist*=0.9;
cout<<"This is the distance after the fall. "<<dist;
dist++;
time++;
cout<<"The time is now "<<time<<". The distance is now "<<dist<<". \n";
}
cin.get();
}[/high]
 
Bug-gone-it!

quantyst wrote:

"2. A bug, beginning from the bottom of a 10 meter hole, crawls up at the rate of one meter per hour, but at the strike of every hour the bug falls back one-tenth of its total displacement from the bottom. How long does it take the bug to get itself to the edge of the hole opening?"



IlyaKEightSix wrote:

"2) As for the second one, I wrote an algorithm for that and after tweaking it, I believe the answer is that the bug never quite reaches the edge of the hole. It gets infinitesimally closer for an infinitely long time, but never reaches the ten meters. Poor critter."



Here's quantyst's solution:

The bug can never reach the edge no matter how long or how many times it tries. Here's why:

As long as bug's position is less than the 9 meter level in the hole, it can never get to a position above or at the level 9 meters from which it can crawl up further.

Let x denote the position of the bug at any time before it has reached the 9 meter level.

So, x<9.

Now, the bug crawls up for 1 meter to position x+1,and we have: x+1<10.

Now the bug falls back by one-tenth of this new position. Subtracting one-tenth (.1) of any number from itself is the same as multiplying the original number by nine-tenths(.9).

So, we multiply both sides of x+1<10 by nine-tenths (.9):

(.9)*(x+1)<10*(.9)=9.

So, the new position is (.9)*(x+1) and is AGAIN less than 9.

What this proves is that as long as the bug is below the level 9 meters, it will continue to stay below level 9 meters.
 
14) What comes next in the following sequence ?
1, 4, 5, 6, 7, 9, 11,...

Any number will do!

Here's why I say this: For any number (even an irrational number) as the eighth number following the first seven terms of the sequence, I can find a formula that generates the first seven numbers as given, and that generates the eighth number as the new arbitrary number.

Unless, for the purpose of making the solution unique, certain additional constraints are in advance specified, sequence questions are no good.
 
Deciphered ... awry!

14) What comes next in the following sequence ?
1, 4, 5, 6, 7, 9, 11,...

Here's a personally silly response, but any one is welcome to take it seriously.

Let x denote the eighth number in the sequence. So, we have:

1, 4, 5, 6, 7, 9, 11, x.

Now draw a vertical line through the center and subdivide the terms into two groups, one on the left, the other on the right:

1, 4, 5, 6| 7, 9, 11, x.

Now add the numbers symmetrically a pair at a time:

(1+x), (4+11), (5+9), (6+7),

or

(1+x), 15, 14, 13.

So, (1+x) must be 16.

(1+x)=16.

So, x=(49.00807)^(-.05607).



Please see my previous note regarding this problem.
 
MAXimize!

Suppose a and b are two positive rational numbers and let R be any positive real number.

For example:

(1) a=3/8, b=5/6, R=(37)^(2/5),

(2) a=5/12, b=1/10, R=(4067)^(1/3).

Define the function f(x,y)=ax+by. Maximize f(x,y) subject to f(x,y)<R where x and y are non-negative integers, for each of the above cases.

[How would the problem change if we allowed x and y to be any integers?]
 
14) What comes next in the following sequence ?
1, 4, 5, 6, 7, 9, 11,...


I was thinking at 13, too, by applying n = Floor{[(n-1)+(n+1)]/2} rule to each number. But, 1 denies it.

Hint: Has to do with the spelling of each number. :)
 
Suppose a and b are two positive rational numbers and let R be any positive real number.

For example:

(1) a=3/8, b=5/6, R=(37)^(2/5),

(2) a=5/12, b=1/10, R=(4067)^(1/3).

Define the function f(x,y)=ax+by. Maximize f(x,y) subject to f(x,y)<R where x and y are non-negative integers, for each of the above cases.

[How would the problem change if we allowed x and y to be any integers?]

This is a trivial problem, for any instance in which x and y are non-negative. It's a simple application of the branch-and-bound algorithm from integer programming. The function is a collection of points bounded by the linear programming feasible space when the integer constraint is relaxed, in n+1-space, where n is the number of variables.

For your first example, here is the AMPL source code I used (it's a C-based optimization language with built in simplex, branch-and-bound, and non-linear-programming algorithms (though I'm not sure which NLP algorithms it uses))

var x>=0, integer;
var y>=0, integer;

maximize function: 3/8*x+5/6*y;
subject to constraint: 3/8*x+5/6*y<=37^(2/5);

And here is the output:

ampl: model quantyst.mod;
ampl: option solver cplex;
ampl: solve;
CPLEX 10.0.1: optimal integer solution; objective 4.208333333
2 MIP simplex iterations
0 branch-and-bound nodes
ampl: display x;
x = 9

ampl: display y;
y = 1



When I remove the non-negativity constraint, AMPL crashes, from which I can conclude that there is an infinite set of equally good solutions, which require more constraints to arrive at a single solution.

All other instances are solved as trivially.
 
Untrivialized ...

his is a trivial problem, for any instance in which x and y are non-negative.

Why is it trivial? Because? Because?

It's trivial because the code did it. In that sense it is trivial! And so are many other problems.

Now, do the same problem analytically, without the advantage of a computing machine (other than the organic one). Now, it becomes fun and non-trivial. The point is: Can we find a non-brute-force method to do the problem?
 
The non-brute force method is drawing the feasible area geometrically and finding the solution in 2 or 3-space. After that, it's just repeated iterations of the simplex method with constraints that the decision variables must be integer values.

At least that's the way I've done this problem before, but I'll be delighted to see a different solution.
 
The non-brute force method is drawing the feasible area geometrically and finding the solution in 2 or 3-space. After that, it's just repeated iterations of the simplex method with constraints that the decision variables must be integer values.

At least that's the way I've done this problem before, but I'll be delighted to see a different solution.


O.K.

I will give a limited answer to a special case of the problem. The special case involves the one in which x and y are allowed to be any integers. The insight we take from this case might be useful in finding a solution for the case where x and y are non-negative integers.

Here it goes.

First notice something special about a and b, they are rational. In many equations and inequalities, a rational can be converted to an integer.

Look:

a=3/8, b=5/6, R=(37)^(2/5),

f(x,y) = ax + by = (3/8)x + (5/6)y<R=(37)^(2/5).

The least common multiple of the denominators of a=3/8 and b=5/6 is 24.

Now, we multiply both sides of the inequality by 24, the least common multiple of the denominators a and b, to get:

24*((3/8)x + (5/6)y) < 24*((37)^(2/5)) = 101.7400464...

So,

9x + 20y < 101.7.

Now, it turns out that the greatest common divisor of 9 and 20 is 1. (***)

Thanks to a basic but important theorem in Number Theory, there exist two integers x and y such that ax+by=gcd(a,b). We can easily find two integers x and y such that:

9x + 20y = gcd (9,20) = 1.

For example, for x=9 and y=-4, we have 9(9)+20(-4)=1.

We can now multiply both sides of this preceding equality by 101 to get the maximum integer sum satisfying the inequality:

9(909)+20(-404)=101 < 101.7...

Dividing both sides of the preceding by 24 gives us:

(3/8)(909)+(5/6)(-404) < R.


>>>> The 'solution' above should only serve as an insight as we are still far from an analytic solution for the constrained case of both x and y being non-negative.



--------------------------------------------------------
In the line (***), if gcd>1, we would divide both sides by this gcd and proceed the same way.
 
My first post

I am new here and want to say this place is very informative. Thanks everyone.
I was trying to solve the problems (1) and (2) posed by quantyst. This is where I got so far.
Apologies if I am wrong.

Problem 1

9x + 20y = 101 , x,y are nonnegative integers. (eqn 1)

101 = 2 (modulo 3)
9x =0 (modulo 3)
20 = 2 (modulo 3)
Hence y has to be of the form 3k+1,k>=0

Rewriting eqn 1,

9x + 60k =81

3x + 20k =27
Again, k has to be a multiple of 3 for this to have a solution

Only solution k=0, hence y=3k+1=1, x=9
ANS: (x,y)=(9,1)

Problem 2
Multiplying the equation by gcd(12,10)=60

25x + 6y <= 60*(4067^(1/3))
25x + 6y = 957

25 = 1 (mod 6)
957 = 3 (mod 6)
So x has to be of the form 6k+3

Rewriting the original equation,

25(6k+3) +6y = 957
150k + 6y =882

25k + y =147

so the solutions are x=6k+3, k=0,1,2,3,4,5, y=147-25k

ANS : (3,147), (9,122), (15,97), (21,72), (27,47), (33,22)
 
Back
Top