Uniform Variables: Smaller Below Larger Squared
Updated
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 [0,1] case in the first example. 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) → doubleExamples
Example 1
upperBound = 1.0return = 0.6666666666666666In 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.3333333333333333On 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.9166666666666666For 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.0Both variables equal zero, so 0 < 0 is false.
Constraints
- For this exercise, assume
upperBound = 0or0.000001 <= upperBound <= 1000. - The two variables have the same continuous uniform law when the upper bound is positive.
- Return a
doubleprobability from0through1.
More IMC Trading Phone Screen questions
- Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
- Combination Sum with Unlimited ReusePHONE SCREEN · Seen Dec 2025
- Valid Range of a Three-Outcome Probability ParameterPHONE SCREEN · Seen Dec 2025
- Expected Fishing CatchPHONE SCREEN · Seen Dec 2025
- Count Routes Through a City GridPHONE SCREEN · Seen Nov 2024
- Expected City Arrival and Return DaysPHONE SCREEN · Seen Nov 2024
- Stationary City Population SharesPHONE SCREEN · Seen Nov 2024
- Maximum Falling Path SumPHONE SCREEN · Seen Nov 2024
- Trading Profit Percentage ChangePHONE SCREEN · Seen Feb 2024
- Poker Suit Expected ProfitPHONE SCREEN · Seen Sep 2023
Similar questions at other companies
- Parking Fee CalculatorBreeze · PHONE SCREEN
- Merchant Payout Reserve CalculatorStripe · PHONE SCREENStripe interview questions
- Sqrt(x)LinkedIn · PHONE SCREENLinkedIn interview questions
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Circular Primes Below a LimitAmazon · PHONE SCREEN
- Palindrome NumberKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
- Streaming AverageXantium · PHONE SCREEN
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN