Uploaded by Houssam FOUKI

General Practice Questions - updated

advertisement
General Practice Questions
Example/recommended questions are listed below, primarily taken from the below recommended reading list.
RECOMMENDED READING
“Heard on the Street: Quantitative Questions from Wall Street Job Interviews” by Timothy Falcon Crack
“A Practical Guide To Quantitative Finance Interviews” by Xinfeng Zhou
‘Cracking the Coding Interview’, Gayle McDowell
‘Elements of Statistical Learning’ - https://web.stanford.edu/~hastie/Papers/ESLII.pdf
If struggling to get to grips with ESL – ‘Introduction to Statistical Learning’ or ‘All of Statistics’
For stat arb/quant trading:
http://www.amazon.com/Quantitative-Financial-Economics-Foreign-Exchange/dp/0470091711
‘Quantitative Financial Economics’, Keith Cuthbertson
http://www.amazon.com/Quantitative-Financial-Economics-Foreign-Exchange/dp/0470091711
‘Quantitative Financial Economics’, Keith Cuthbertson
If interested to sit down with a pen and paper and work through:
1. Quantitative Financial Economics/Complete guide to capital markets
2. Statistical Arbitrage: Algorithmic insights and techniques
3. Trading and Exchanges: Market Microstructure for Practitioners
TOPICS








Maths
Statistics
Probability
Mathematical Finance
Brain teasers
Python Coding
Trading intuition
Questions on research/strategies/experience
DATA STRUCTURES








Dynamic Array
Linked List
Stack & Queue
Hash Tables
Binary Search Tree
Binary Heaps & Priority Queue
Graphs
Trie
ALGORITHMS












Bit Manipulation & Numbers — difference btw Unsigned vs signed numbers
Stability in Sorting
Mergesort
Quicksort
Heapsort — Sort it in-place to get O(1) space
Binary Search
Selections — Kth Smallest Elements (Sort, QuickSelect, Mediums of Mediums) — Implement all three ways
Permutations
Subsets
BFS Graph
DFS Graph
Dijkstra’s Algorithm (just learn the idea — no need to implement)








Tree Traversals — BFS, DFS (in-order, pre-order, post-order): Implement Recursive and Iterative
External Sort — No implementation; Just know the concept.
NP-Complete (Video) — Just know the concept
Topological Sort
Detect cycle in an undirected graph
Detect a cycle in a directed graph
Count connected components in a graph
Find strongly connected components in a graph
BRAINTEASERS
1. 3 jars, 1 full apples, 1 full peaches, 1 is both. Each jar has stickers but stickers are not on right jars. Choose one
fruit from one jar and work out which is which. Solution, take one from the both jar, but as its incorrectly labelled it
will be either apple or peach depending on what comes out.
2. You have the choice to invest in either a risky asset or a risk-free asset. The risky asset has a 50% chance of
returning 10% and a 50% chance of returning -10%. The risk-free asset has a guaranteed return of 5%. Which
asset should you choose to maximize your expected return?
3. You are given a choice to invest in two different portfolios, A and B. Portfolio A consists of 50% stocks and 50%
bonds, while portfolio B consists of 80% stocks and 20% bonds. The expected return for stocks is 10% and the
expected return for bonds is 5%. Which portfolio should you choose to maximize your expected return?
4. 4 people need to cross a bridge, 1st person takes 1 min, 2nd takes 2 min, 3rd takes 5 min, 4th takes 10 min. Want
everyone to cross the bridge in the fastest way possible. Only 2 can cross at the same time. They need a lamp to
cross the bridge also. What is the minimum way/time for all 4 to cross the bridge?
5. Imagine we cut a hole in the top of the Earth and hollow it out. Then we being to pour water from an everyday tap
into the hole. The flowrate of water doubles every second. How long would it take to fill the Earth? (Must estimate
volume of earth and tap flowrate, should end up with a geometric series in your answer)
6. Is there a power of 2 that have a 9 as a leading digit?
7. You have 100 wine bottles and you know one of them contains a poison, which kills you one day after you drink it.
You have a banquet the next day and you want to locate the poisonous bottle before it. You can hire wine tasters
that can try multiple bottles. What is the minimum number of wine tasters you need to hire in order to locate the
poisonous wine bottle?
8. We have four positive integers a,b,c,d. Out of the 6 sums we can produce from pair of the four numbers (namely
a+b, b+c, a+c, c+d, a+d, b+d). You are given 5 sums, not knowing which sum corresponds to which pair. How can
you determine a,b,c,d?
9. 3 blue hats and 2 red hats in a room. The room is dark. 3 people go in and each put on a hat. They do not know
what hat they have put on. They then go out into the light and look at each other but not themselves, however the
3rd person is blind.
 The 1st one whispers, I don't know what colour I'm wearing.
 The 2nd one hears this whisper, then whispers I don't know what hat I'm wearing.
 The 3rd and blind one hears this whisper and then says, I know what hat I'm wearing.
 What hat is the 3rd person wearing?
10. Two envelopes, one with x amount of money and the other with 2x. You randomly choose one and see how much
in it. Which envelope should you take?
PROBABILITY
1. Russian roulette- two bullets in a gun, spins once, survives should he spin again?
2. Suppose you make a cake that is 1kg and you throw randomly some chocolate chips in it. How many do you have
to put so that a random slice contains at least one chip with probability at least 99%.
3. Calculate the mean of the maximum of two independent uniform random variables etc.
4. There are two independent variables – what is the probability that one of them is greater than zero?
5. How can you test if a coin is fair? Given an unfair coin, how can you use it to create fair events?
6. You are given a fair dice and roll it 5 times. What is the covariance/correlation of the occurrence of number of 1
and occurrence of number of 2
7. You toss a coin 100 times, what is the probability of 60 being heads? What is the probability of getting at least 55
heads?
8. You toss a coin 100 times get 60 heads 40 tails. Is the coin unbiased? Test with 5%.
9. Given two coins, one is unbiased and the other is biased with 2/3 head 1/3 tail. Now we toss a coin once and get
head. Then we toss another coin 3 times with head, head, tail. Which one has higher possibility to be a biased
coin and calculate the possibility?
10. Expected number of fair die rolls until you get all numbers.
11. You have a fair coin, what is the expected number of flips before you get your first head?
12. Roll a coin, what is the expected number of rolls before getting a row of five heads?
13. What is the expected amount of flips until you can get three heads in a row?
14. You have 1000 coins, 999 coins are fair and 1 coin has 2 heads. You take a coin, flip it 10 times, and obtain 10
heads. What is the probability that you picked the unfair coin?
15. You have 10 fair coins and you flip them all. What is the probability that the number of heads you get is even?
16. Coin flips. Gain expectations, variance when you do it 100 times.
a. Different games derived from coin flip.
17. You have n people in a hotel with n rooms. The keys are randomly distributed. What is the probability of having no
one with the key to his or her room?
18. There are n bugs on a line, each of them with a different size and moving in the same direction. Larger bug
moves faster than the smaller one, and when a larger bug catches a smaller bug, the larger bug eats the smaller
one. Question: after long enough time, what is the expected number of bugs?
19. There are N2 candies in an N x N square matrix, with 1 candy broken. Each round, two people take the column or
row, turn by turn, trying to avoid being left with the column/row that contains the broken candy. Should you be the
first or second person? Why?
20. Given a box with a specific weight, compute how many ways to put some packages in it.
21. You are given two coins; one is fair the other one is bias. Choose a coin, throw it a few times and note down the
results, how do you know which one is fair?
22. 100 people in a circle, the first one has a gun, kills the second and pass it to the third, and so on until there is only
one remaining. What was her initial position?
23. 50 people are playing head to head games, how many games will there be if every player has to play each other
person once.
24. When tossing a coin, what are the expected number of throws before getting the sequence – heads, tails, and
heads?
25. Outline the general formula for coin tosses where you get n number of heads in a row.
26. Calculate the number of trailing zeroes for 100 factorial.
27. Determine the positive value of x where x to the power x, x times equals 2.
28. There are 26 black (B) and 26 red(R) cards in a standard deck. A run is number of blocks of consecutive cards of
the same color. For example, a sequence RRRRBBBRBRB of only 11 cards has 6 runs; namely, RRRR, BBB, R,
B, R, and B. Find the expected number of runs in a shuffled deck of cards.
29. "You have $1 and a 50/50 chance to double or lose it. How many times can you play this game before expected
returns turn negative?"
30. Two random variables: X and Y, independent. What is the probability that X+3Y > 0. Same two variables: Joint
probability that X > 0 and X+3Y > 0
31. 1 coin with 2 Heads, 999 normal coins. Pick one at random, flip 10 times -> 10 heads. What is the probability that
you picked the 2 heads coin.
32. You have 2 variables x and y, following a Binomial law p=0.5. Knowing x=y 47% of the time, can we predict y
given x?
33. You are given a fair coin (probability 1/2 of H or T). Devise a procedure to simulate a random variable with 3
outcomes that are equally likely (probability 1/3 each).
34. 5 people on a round table seated randomly. 2 have red shirts, 3 have blue shirts. What is the probability that the
two red shirts are sat next to each other?
35. You can throw a 6 sided die up to 3 times. Your score would be the number of the last roll. E.g. if you roll 2, then a
5 then a 3. Your score would be 3. If you did this optimally, what is your expected score?
36. A dice game. Stop when you first get 6. You will get a reward of 1/(number of throws). What’s the value of the
game?
37. Roll a dice 5 times. Denote X as the number of 2s obtained and Y as the number of 3s obtained. Calculate the
covariance.
38. You toss a coin 100 times and observe 70 heads. Find the confidence interval on the true probability of heads.
39. There is a single-cell organism that can have one of four states with equal probability
a. Die
b. Nothing happens
c. Divides into 2 cells
d. Divides into 3 cells
What is the probability that the creature will become extinct?
40. Expected number of tosses before getting the sequence – HHHH, then for HTTH
41. What is the expected number of coin throws before you get a HH sequence. Then what about for HT? Without
calculation, is the number of throws to get HT, bigger or smaller than throws before getting HH?
42. Which is more likely to be biased – a coin you flipped and got H, or a coin you flipped three times and got HTH?
43. How many times do you need to throws a fair 6-dice before getting a 6 for the first time?
Solution: Using recurrence formula for the expectation E : E= 1 + 5/6 E, we find 6
44. What is the probability under the uniform law over a circle of the following event: 8 iid points fall within the same
semicircle (in 8 draws).
45. Three regular 6-sided dice are thrown independently. What is the probability that the observed numbers are in a
strictly increasing order?
46. A unit length stick is broken into three pieces according to a uniform distribution. What is the probability that the
pieces can form a triangle?
47. There a coin that turns out heads with a probability of b, b following uniform distribution. After one throw that turns
out head, what is the probability distribution of b?
48. Sharpe ratio is 1, after 4 years of trading, what is the probability of losing money?
49. You are playing a game where you roll a fair, 6-sided die.
 If you roll x, you get x dollars. If you choose, you can reroll up to two times. How much would you pay to
play this game?
50. You are given two coins, one is flipped 10 times and shows 4 heads. The other is flipped 1000 times and shows
450 heads. Which coin would you pick to flip if you would double your money by seeing heads?
51. Throw a coin 1 million times and get 510k heads and 490k tails, is the coin biased?
52. You have a fair and one biased (2/3 heads) coin.
 You randomly pick one, throw once and get heads
 You randomly pick one again, throw 3 times and get heads twice
Which one is more likely to be the biased one?
53. Given a fair coin, simulate three events with equal probability. What is the expected number of coin tosses?
54. The same coin used at gaming: throw such a coin and make a guess. If right get 1 dollar, otherwise lose 1 dollar.
What will be the strategy? What is the expected value of such a strategy for one day? For one year? What is the
std of one year? What is the probability of losing money after two years?
55. You can roll up to 3 dice, and keep the money shown on the last roll. What’s the optimal strategy and expected
value of this game?
56. There are 5 foxes and 7 dogs in a row (in random order), what are the expected number of fox dog pairs?
57. What is the probability of rolling an even number of heads if you toss n=8 fair coins? How about for n=9 coins?
What about for an arbitrary n?
58. There is a queue consisting of 8 men and 9 women, how would you calculate the expected number of "pairs"
where a man is standing next to a woman.
59. There are two coins: a fair coin and a biased coin with a 2/3 probability of landing heads. After drawing the first
coin once and obtaining a head, and then drawing the second coin three times and getting 2 heads. Determine
the probability that the first coin was biased.
60. What is the probability of you throwing a coin 9 times and getting even number of heads?
61. You have a HH coin and a HT coin, with a randomly selected coin, you throw 4 heads in a row. What is the
probability you had thrown a HH coin?
62. Dice roll: 1 2 3, I get 1 dollar and roll again. 4 5, I stop the game and I keep the money. 6, I stop the game and I
get no money. Expected profit?
63. Given a sphere. The points on the surface are uniformly distributed. Calculate the expectation and variance of the
x-coordinate of the points.
64. I toss a coin 10k times, I get 5100 heads. Is the coin biased?
65. We flip coin A 100 times and it comes up heads 60 times. We flip coin B 1000 times and it comes up heads 550
times. Which coin is more likely to be biased?
66. If I hit an archery board with probability p, and so do you, what is the probability that I hit the board first? (I take
the first shot)
67. 3x3x3 cube made of smaller blue cubes. The outer face of big cube is painted red. I disassemble and pick a block
at random. I roll it and see 5 blue faces, what is the probability that the face on the table is also blue? Answer: ½.
68. Given random variables X, Y follow iid standard normal distribution. Compute P(X+Y >0|X>0)
69. You have to cross N islands, each with 2 bridges between them. Each pair of bridges has one faulty one. If you
cross a faulty bridge, you go back to First Island. What is the expected number of bridges you cross to get island
N.
70. Two Coins – One biased with 2/3 P(Heads) and the other fair. Flip one and its heads, flip the other 3 times and
get 2 heads – which one is the biased coin?
71. You simulate 3 fair possibilities with a coin flip, how would you do it if the coin was biased, and how many flips
would you expect until you finally reach a decision?
72. Candies in the bag: only eats one color, put back the other color if drawn. Expected number of draw a until eat all
the candies of one color.
73. Alice and bob are playing a game with 2 dices.
a. In game 1, Alice has a dice with 5 faces from 1 to 5 and bob has a 10 faced dice from 1 to 10.
b. In game 2, Alice has a dice with 50 faces from 1 to 50 and bob has a 100-faced dice from 1 to 100.
c. Alice wins if she throws a number lower than Bob’s number. Which game Alice should choose to increase
her chances of winning?
GAME THEORY
1. In a game, you and two others each think of a positive integer. You win if you pick the smallest number that
nobody else guesses. (If all three guess the same number, nobody wins). What is the optimal strategy?
2. We play a game. You are given a 6-sided fair dice. Say the outcome is X. You may choose to receive X dollars, or
re-roll once. If you re-roll, you must take the outcome of the re-roll (no going back to the first roll). What is your
strategy and expected value of this game?
3. Suppose you draw integer N uniformly between 1-1000. Then draw 10 integers uniformly from 1-N. Suppose you
are shown the 10 numbers, and the game is you win 1$ if you guess N right and lose 1$ if you guess N wrong.
What would be your strategy?
4. Suppose there are a countably infinite number of boxes, labelled with integers from infinity-to-infinity. Suppose
there is a rabbit starting at position p, and at every time step it will move m boxes. The m and p is fixed but
unknown. At each time step, you could inspect 1 box to see if the rabbit is inside or not. What is your strategy to
find this rabbit?
5. You get to play three games against your father/brother; either FBF (father brother father) or BFB. You have 5%
chance to win against the brother and 50% win chance against the brother. Which of the two settings (FBF/BFB)
would you choose to maximize your chance to win 2 consecutive games?
6. How would you find the value of a game where you can reroll a dice up to 3 times?
a. Would you pay more or less, to play a game with the maximum of 3 dice?
b. Would you bet 100x the amount to play once, or bet 1x the amount to play 100 times?
7. Play a game where you play against me. It costs £1 to play and you win £1 if it lands heads. What is the
probability of me bankrupting you if you start with £2 and I start with £1.
8. Open ended discussion on probability distribution
 Triple or nothing game
 Start with initial capital
 You can make bets with a fraction of your capital – if you win, you have a 50% chance of tripling your bet,
50% chance of it going to 0.
 There is no specific answer, more discussing your thinking process
 What is your expected returns after n games?
 How would you optimise your returns?
 How should you play the game if you are risk averse? How would this differ if you were risk friendly?
 How would the probabilities differ?
9. We play a game. You are given a 100-sided fair dice. You may pay 1 dollar to roll the dice. Say the outcome is X.
You may choose to 1) receive X dollars, and immediately stop the game; or 2) give up the outcome and re-roll.
What is your strategy to maximise expected value? (Computations are complex, you don't have to find the final
numerical value).
10. Describe an estimator for the shift in a Cauchy distribution, how fast does it converge?
STATISTICS/MATHEMATICS
1. Questions on statistics - different kinds of regression (basic, ridge and lasso).
2. Other methods of estimation like maximum likelihood – giving examples of evaluation of the validity of an
estimation.
3. Suppose you have a number of recommendations about buying or selling various stocks. How do you decide
what to do?
4. Given 2 identical Gaussian curves with mean and standard deviation equal to 1. If you combine the distributions,
what are the parameters of the resulting distribution?
5. X and Y are vectors of size n, b is the coefficient of the regression Y to X and b' is the coefficient of the regression
X to Y. What is the relation between b and b'?
6. Brain Teaser on Algo: two containers, which can only pop in from the end, pop out from the head, one is full the
other is empty, how to make these two containers combined to do a few operations.
7. Estimate the probability of draw from a normal distribution N (0, sigma^2) to be between -2*sigma and 2*sigma.
The estimation was done using binomial experiments.
8. X, Y two iid normal centered variables with 0 sigmas. What is the probability of X>=0 conditioned on X+Y>=0?
9. Explain difference between and discuss joint and conditional Gaussian distributions.
10. Given a dataset with 500 rows and 1000 columns (features), construct a model.
a. Explain the different models (2-3 models).
11. What is the equation for the distribution of time between two events for a Poisson process?
12. Given values X and Y, give the probability that X is positive and Y is negative.
13. If we fit a linear regression model Y=aX, and a different linear regression model X=cY, what’s the relationship
between a and c?
14. Suppose you have a regression model Y=aX, how can you change the model to make it so that the prediction of
your model today are not very far from historical model’s predictions? (making it so that Y(t+1) is close in value to
Y(t))
15. Bayesian reasoning: If you know someone is COVID positive there is a 99% chance they test positive, if you know
they are negative then there is a 99% chance they test negative.
a. If 25% of the population have COVID, what is the chance of a positive result if you test at random?
16. How would you simulate a uniform distribution of points inside a unit disk?
17. What is the number of integers between 1 and 10^12 whose cubic ends with 11?
18. You are given a linked list, how can you sample an element uniformly at random?
19. Expected number of samples of Uniform[0, 1] variables before it reaches a sum greater than 1?
20. Given Y = a + bX+ epsilon, how can we estimate a,b using mean squared errors? How can we estimate a and b
using maximum likelihood? Under what conditions the estimators will be the same?
21. Supposed that we have a dataset. If we have wrongly dealt with them and each entry enters twice. What is the R2
and the t-statistic of the output compared to the original one?
22. How do we select models?
23. How do we deal with overfitting?
24. We have a huge prediction model. How do we reduce the size?
25. We have X1, X2 two strongly correlated distributions. When we add the input of X2 to predict X1, why does the
variance of the model increase? (For example, for a linear regression Y = aX1, the variance of a will increase).
26. We want to construct a portfolio. We have stock A and stock B with the same expected return, and the standard
deviation of A is 20%, B 30%, the correlation coefficient between A and B is 0.5. How to minimize the variance?
27. What is the difference between LASSO and Ridge?
28. Within supervised learning, there are a few ensembling methods. What is the difference between boosting and
bagging?
a. What are examples of algorithms that use these? (Answer: e.g. adaboost and random forest)
b. For these examples, which one do you think has higher bias? higher variance?
29. X and Y are i.i.d standard normal. What is i) P(X > 0), ii) P(X + 2Y > 0), and iii) P(X > 0 and X + Y > 0)?
30. In simple linear regression of y on x, we have the optimised equation y = k x + b. In that of x on y, we have x = k' x
+ b'. We are given k = k'. What are the possible values of k?
31. Machine makes rod of length 1m with 10% error. What is the error of 10 combined rods?
a. What if the error between pairs of rods has some correlation r (-1<r<1)? Ans: sqrt(10)% initially. If r =-1
then error is zero. If r=1 then error is 10%, increasing in between
32. If I add an extra parameter, which is entirely random to a linear regression, what happens to total error? (goes
down as minimising over more things, even though it’s random)
33. Let X, Y be uniform random variables on [0, 1]. Find least squares regression coefficients a, b, c for XY ~ aX + bY
+ c.
34. You have to weight an item and have 2 scales. The scale 1 gives a weight w1 and the scale 2 gives w2. Without
any additional information, how would you estimate the true weight of the item? The scale 1 has an error e1 and
the scale 2 an error e2, so that the scale 1 has a normal distribution with std sigma1 and the scale 2 a normal
distribution with std sigma2. How do you estimate the true weight?
35. I have a garden with n (~ 100,000) fountains at positions 1, ..., n, fountain i sprays water in a radius r[i] (1 <= r[i]
<= 100). Find minimum number of fountains required to water all points on the garden.
36. Each bacteria splits each second into some number of bacteria that is Poisson distributed. All the splits are not
correlated. What would be the distribution of bacteria after t seconds if we start with only one? (Splits to 0 means
die splits to 1 means nothing changed).
37. Let X,Y,Z be three random variables and assume their correlation rho(X,Y)=rho(X,Z)=rho(Y,Z)=p are all equal.
What bounds can you give on p? How does this generalize to n random variables?
38. You have a line segment 1m long, and you place n insects randomly (uniformly) on it. Each insect starts moving
either right or left (50/50 chance) at 1m/s speed, and when two insects meet each other they bounce off each
other and start moving in the opposite direction. When they reach the extremities of the segment, they fall off.
After how long do you expect the segment to be empty?
39. How do you estimate 2^40? Let’s say your estimate is 10^12. How do you check that it is within error range 5%?
40. You are given N strings. Each step you choose randomly two ends (can be in different strings or the same string).
If they does not belong to one string, tie them together to form a new string. Otherwise, form a loop and put it
away. What is the expected number of loops? (Solution: consider recursively) What is the asymptotic behavior of
this series?
41. X and Y are vectors of size n, b is the coefficient of the regression Y to X and b' is the coefficient of the regression
X to Y. What is the relation between b and b'?
PROGRAMMING QUESTIONS
The Hackerrank website has challenges you can work through to practice your coding skills. There is a dynamic
programming section containing problems that you can work on in timed conditions.
https://www.hackerrank.com/domains/algorithms/dynamic-programming/page/1
1. You have a stack of coins in rows, and water drops. Each water drop can stack on top of coins until it overflows.
So for instance if you have the coins, you can fill up to 2 water drops. Write a program to figure out the total
number of drops you can fill in.
2. Find the longest increasing subsequence in a given array. (First assume that the subsequence should be
continuous and then the general case)
3. Code a function that takes as input a number (float) and precision (int). The function computes the square root of
number up to precision.
a. for example: sqrt(3, 0) = 1, sqrt(3, 1) = 1.7, sqrt(3, 2)= 1.73
4. Code Fibonacci. What is time complexity?
5. In a list of integers, find the biggest sub list with increasing numbers. The order shall stay the same but you can
skip some numbers.
a. Example: [1,2,2,3] shall return [1,2,3]; [1,2,6,3,2,4] shall return [1,2,3,4]
6. Find max size of sub-squares in a matrix (dynamic programming)
7. Given an array Arr[ ], you can switch the values of two adjacent elements and each element can be switched at
most once. How do you maximise the sum over the indices i of Arr[i]*(i+1)?
8. Given an array with positive and negative transaction values, find a sub-array to make the value positive.
9. Contiguous subarray of maximum sum within an array (give indices of the array and the maximum sum).
a. Given an array, how to design a program finding a subarray whose sum equals to 0.
10. Hypothesis: test a feature that matches up with data 47% of the time, is that significant, how would you test it?
11. Given two variables with similar mean squared errors, how would you test if they are accurate?
12. Have a string of parameters with open brackets. You are required to ensure all brackets are closed by inserting
additional brackets. Have to calculate the number of brackets to close all parentheses.
13. Dynamic programming question. Given a list of integers and definition of a parameter, k. k is the amount of times
you apply an operation to 1 element. Have to apply a sequence of operations and calculate the minimum sum to
apply a sequence of k.
14. Produce a function which two inputs: an integer k and a list of random integers of length n. the output should be
the number of distinct pairs such that one number in the pair + k equals the other.
a. You can use the same number twice (for instance use 1 to create the pair (1,1))
b. Example: the list [1,2] has three distinct pairs: (1,1), (1,2) and (2,2). (The same goes for [1,1,1,2]). If k = 1,
then only (1,2) satisfies the condition, so the output should be 1.
15. Given an array, code an algorithm to find a (contiguous) sub-array which has the maximum sum
a. What's overfitting?
b. What is Monte Carlo?
c. Discussion about statistical learning methods, their benefits, cons etc.
d. Questions about black Scholes and option pricing.
e. Questions about call/put options and hedged portfolio.
f. Discussion about bootstrapping and swap curve building
16. Partition a list in 2 sublists, the first should be shorter and of greater sum than the second?
17. You have n stairs. You can take either 1, 2 or 3 steps. How many ways are there to climb the stairs?
18. You have two arrays A, B of length n. An action is to take two indices 0 < i, j < n, swap the values in A[i] and B[j].
After k such actions. How many unique numbers are present in A?
19. Write a function max_average(a) that takes an array of integers 'a' as an input and output the largest average of
any subarray of 'a'
20. A subarray is any array consisting of consecutive elements of 'a'. E.g. if a = [a1, a2, a3, a4], then [a2, a3, a4] is a
subarray of length 3 but [a1, a3, a4] is not a subarray.
21. Find the largest sum from a contiguous subarray. Solution: Set variables called 'max_sum' and 'current_sum'.
Iterate once through the array. Set max_sum to current_sum if current_sum >= max_sum. Reset current_sum to
0 if current_sum becomes negative.
22. Find the number of occurrences a 3-letter string can be found in a larger one (e.g., SHL in SSQHUL is found
twice).
23. Given an array of integers, find the subarray with the largest sum and return its sum – maximum subarray
question.
24. Given a list and an integer, check if the integer can be written as the sum of elements in the list.
25. Given an m x n binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area –
maximal square question.
26. There are two strings such as a=abc#abc#’ and b=’ababb#’and the ‘#’ denotes a backspace in the keyboard
(delete the former character). Check if the true a and b is the same.
27. Given a list such as. [3, 2, 1, 4, 6, 5], get the maximum n such that after split the list into n parts and sort each
part, the final list would be a non-descending list. The answer is 2 since you can divide it to [3, 2, 1] and [4, 6, 5],
then sort them and get [1, 2, 3] and [4, 5, 6], combine them and you get a non-descending list.
28. Given a list of movie durations, you have to find out the minimum day of watching them. You can combine
movies, but each day you cannot watch more than 3 hours.
29. A file uploading background. Given what positions are occupied, you have to figure out how to fill the rest of
positions by 2^n size of files.
30. Whether you know about the merge sort and quick sort. What is the corresponding time complexity?
31. What is object oriented programming? Give an example of a project you’ve used OOP in before.
32. Give the longest subarray which sums to zero.
33. Given a sphere in 3-D with points (x,y,z) randomly distributed on its surface, what is the expectation E[x] and
variance Var[x] of coordinate x ?
a. Solution: by symmetry of distribution, E[x] = coordinate x of the center of the sphere. For the variance,
one might notice that the variables x,y,z are equally distributed, therefore one can compute E[x^2] using
the equation of a sphere ( E[r^2] = E[x^2]+E[y^2]+E[z^2] = 3E[x^2]) and use Var[x] = E[x^2]-E[x]^2 to
compute the variance.
34. You are given an array "arr" of int that you have to traverse by consecutive jumps. Given that you're at index i,
you can jump to any other index within [i+1, i+arr[i]]. Write an algorithm to find the minimum number of jump
require to traverse the array.
a. Solution: use dynamic programming approach by initializing an array dp and fill it using the recurrence
relation : dp[i] = min(dp[i],dp[i+j]+1) with j within 1,...,arr[i].
35. You have an n*1 array of 0 and 1 where 0 represents flower type A and 1 represents flower type B. You are a
florist and can make 2 types of bouquets: AAA ( which costs p) or AB ( which costs q). You can only form
bouquets using adjacent numbers in the array but don’t have to use all the flowers available. Write an algorithm
that computes the maximum total value for all the flower bouquets that can be formed.
36. 17 people (8 males 9 females) sit next to each other. Compute expected number of distinct-gender adjacent pairs.
37. What is Sharpe ratio, what happens to the Sharpe ratio if you omit some days when return was 0 when you
compute the Sharpe ratio. If you have n days with nonzero returns and n days with 0 returns, what are the bounds
on the ratio of the correctly and incorrectly computed Sharpe ratios.
38. Given an integer n, generate the first n non-primary numbers.
39. Give the medians of a sliding window (sliding sublist) of a list.
40. Given an integer array of unique elements, return all possible subsets (the power set). The solution set must not
contain duplicate subsets. Return the solution in any order.
41. Given an integer array, find the subarray with the largest sum, and return its sum.
42. Given two strings a and b, return a Boolean indicating whether they are the same in a case-insensitive way. (For
example, 'a' and 'A', true, 'ca' and 'cA', true, 'b' and 'c', false).
a. Based on the previous question, can you also return true when a and b is the same after you add\delete
one entry in the string? (For example, 'abc' and 'AbcX', true)
43. Estimate pi using Monte Carlo samples.
44. You have 8 men and 9 women in a random permutation. How many opposite sex pairs are there in expectation
(can be overlapping)?
45. You are given an array of size n containing integers (positive or negative). You start outside of the array and are
able to take steps of length either 1 or a prime number ending in 3. At each step you take, the number on which
you are in the array gets added to your score. You must reach the last cell of the array. Design an algorithm that
gives the path giving the maximum score achievable.
 Example: for the array [20, 10, -30, 40], the most optimal path is to take a step of size one and then size three
such that you reach cells 20 and 40 giving a score of 60.
46. Given an array of integers and an integer k, return the length of the smallest subarray that contains k unique
values. If no such subarray exists, return -1. What's the time complexity of this algorithm?
47. A gate is modelled as a n*m grid, unit length of which is 1. A prisoner wants to remove some lines to make a hole.
The vertical lines removed are stored in v[], and horizontal lines are stored in h[]. What is the area of the largest
hole?
48. Given an array, compare every element with the elements before it. Find the largest positive difference and return
it. If the array is not ascending at any place, return -1.
49. Count arithmetic subarray.
a. Problem: Given an integer array `nums` return the number of arithmetic subarrays of `nums`.
50. Given a list of numbers e.g [1,1,3,2,4,2,7,8] and a number k eg 2, how many pairs of values are there in the list
(a,b) st a+k=b. For 2 pairs (a,b) and (c,d) they are different if at least one of c or d is not a or b.
51. Given a number and a precision, write a function that gives the square root of the number to the desired precision
(ie number of decimal points) what is the time complexity?
52. Task: Given a 2-D matrix from 1 to 0, you have to identify ‘islands’ you have to find links in arrays based on coefficients.
53. Given n integers to form an array, and a desired value k, such that the sum of subarray is equal to k. Need to
return the number of possible subarrays which sum is equal to k. Note that subarray is contiguous.
54. Given an array, say the value that appears most often dominates the array. What is the length of the smallest sub
array that has the same value dominating and appearing with the same frequency?
55. Given an array, what is the length of the longest strictly increasing sub array?
56. You have a garden of roses (0) and cosmos (1). They are harvested in specific order (example 010110).
You can make 2 types of bouquets:
 Type 1: 1 rose (0) and 1 cosmos (0) which can be sold at price p
 Type 2: 3 roses, which sells at price q.
To make a bouquet, you can only use adjacent flowers (ie i, i+1, i+2).
Given a serie of flowers (ex 010110), what combination of bouquets should you do to maximise profits?
57. Code up Monte Carlo for approximating PI.
58. Given an array, split number arr[i] to x+y. Minimum number of split needed so that the array has an increasing
order.
59. You have a matrix of 0s and 1s and two possible operations: pick a row and circularly shift it left, or right. Find the
minimal amount of these operations needed to obtain a column full of 1s (return -1 if not possible).
60. There are n rooms, m tunnels between pairs of rooms, and some keys. Each room i contains a key of type r[i],
and the jth tunnel is between u[j] and v[j]. However, the jth tunnel is locked and requires a key of type c[j] to move
through it. Given a starting room s, which rooms can you visit? Which room should you start in to access the most
rooms?
61. There is an array of numbers like [3, -3, 5, -2, -2, -2, -2, 6, -1] and we need to find longest possible subsequence
such that cumulative sum is not negative anywhere.
62. Find sqrt(n, p), which is square root of n with precision p.
63. A frog wants to cross a river by jumping on pebbles. The frog can only skip one pebble at most. Each pebble has
a weight (the number of seconds that the frog should spend on the pebble before jumping again). Knowing that
the frog should be on the first and the last pebble of the way, and given the array with the weights, find the optimal
way to get to the end of the river (the way with the minimum waiting)?
STATISTICAL FINANCE/FINANCIAL INTUITION
1. Define some estimators of volatility.
a. What are their theoretical properties? How do you test their quality out of sample?
b. Closed form solution of linear regression. In what case do you have inevitability issues? Ridge regression
closed form solution.
c. What happens to the spectrum of the matrix you invert? Lasso: gradient descent and conditioning.
2. Asked to describe the research topics and to explain how the results from the research are used
a. How to compute the alpha of the strategy? Which mathematical models are used?
b. What are the conditions in the strategy that trigger a trading signal?
c. Are the performances of the strategy satisfying?
3. Questions about general aspects of back testing and production:
a. What are the main differences for a systematic algorithm between a backtesting situation and a real
trading situation? Which effects can occur during the trading but cannot be backtested?
b. How the automatons trades can be audited?
4. If 2 events happen simultaneously 53% of the time, can I use one as a signal for the other one?
5. What is the definition of Sharpe ratio and how do you calculate it? (annualised Sharpe ratio) - General finance.
6. What variables go into pricing an option? (Strike price, maturity date etc.)
7. How does the bid-ask spread change as the trading day develops?
8. If a particular asset had a Sharpe of 2, what is the probability to lose money within 4 years (mean vs standard
deviation) – uses normal distribution.
9. How do you construct a portfolio to not be exposed to the market?
10. Why would you short a stock? Why would you long a stock?
11. You have a portfolio X exposed to the market at level “c”. How do you reduce your exposure? According to
different cost functions (nb of trade, % amount, %^2), how do you reduce the portfolio’s exposure by minimizing
transaction costs? Do this with intuition and with Lagrangian operator.
12. Create a function, which creates a normal distribution, and create a 2nd, which is correlated with a factor p with
the first one.
13. What are the parameters in a function for pricing options? Given a European option, how would you price the
American option with the same expiration date?
14. Difference between European and American options, which is more expensive?
15. If I have 2 European options and one expires later than the other then which one is worth more?
16. What are the factors that affect the bid-ask spread?
17. How does the index price relate to the market price?
18. What is the most important factor of an alpha?
19. What is the beta?
20. What is the Sharpe ratio? What is the relationship between daily Sharpe and annual Sharpe? What did you
assume?
21. How do you compare strategies after running backtests?
22. Suppose the distributions of the returns of two strategies are the same. What else would you consider in choosing
one or the other?
23. What is Monte Carlo, what do you use it for, then use it to approximate Pi.
24. Can two stocks be positively correlated day-by-day and yet negatively correlated over, say, a year?
25. Suppose we are risk-averse (preferring lower standard deviation), and we have two (stocks? strategies?) A and B
with the same standard deviation but one has higher mean. Which do you prefer?
26. Now suppose A has mean 1%, B has mean 2%, and they have common standard deviation of 1% and correlation
0.5. Construct a portfolio maximising the Sharpe ratio.
27. Given a set of stocks in which you need to allocate a certain amount of money, how do you allocate the money to
these stocks if you want to minimize the portfolio's volatility?
28. Given a fixed portfolio allocation traded by some other counterparties (eg 50% of stock A, 30% of B, 20% of C),
how do you detect trades of this basket of stocks in the market?
29. How is price determined in the after-market auction?
Download