FastPrepUniform Variables: Smaller Below Larger Squared

Uniform Variables: Smaller Below Larger Squared

IMC Trading logoIMC Trading● EasyNEW GRADFULLTIMEPHONE SCREEN
Learn

Problem statement

Two random variables X and Y are independent and uniformly distributed on [0, upperBound]. Return the probability that min(X,Y) < max(X,Y)^2.

For this exercise, assume the common upper bound is supplied as an input, generalizing the reported [0,1] question. The inequality is strict. If upperBound = 0, both variables are zero and the event is false.

Complete uniformSquareProbability(upperBound). Answers within 1e-9 absolute error are accepted.

Function

uniformSquareProbability(upperBound: double) → double

Examples

Example 1

upperBound = 1.0return = 0.6666666666666666

In either half of the unit square, the favorable region has area 1/3. The total probability is 2/3; 1/3 is the complementary event.

Example 2

upperBound = 0.5return = 0.3333333333333333

On this smaller square, integrate twice the area under m^2 and divide by 0.5^2, giving 1/3.

Example 3

upperBound = 2.0return = 0.9166666666666666

For a maximum above one, every smaller value is below its square. The resulting probability is 1 - 1/12 = 11/12.

Example 4

upperBound = 0.0return = 0.0

Both variables equal zero, so 0 < 0 is false.

Constraints

  • For this exercise, assume upperBound = 0 or 0.000001 <= upperBound <= 1000.
  • The two variables have the same continuous uniform law when the upper bound is positive.
  • Return a double probability from 0 through 1.

More IMC Trading problems

See IMC Trading hiring insights
public double uniformSquareProbability(double upperBound) {
    // Write your solution here.
}
upperBound1.0
expected0.6666666666666666
Checking account…