Valid Range of a Three-Outcome Probability Parameter
Updated
Problem statement
Three outcomes cannot happen together. Their probabilities are q, weight*q^2 and 1-q-weight*q^2. Find all real values of q that make these three numbers a valid probability distribution.
weight is a nonnegative integer given as input. The first example uses weight one. The valid set is one closed interval [0, upper]. Return its upper endpoint.
Complete maximumValidQ(weight). Answers within 1e-9 absolute error are accepted.
Function
maximumValidQ(weight: int) → doubleExamples
Example 1
weight = 1return = 0.6180339887498949Nonnegativity requires q >= 0 and q+q^2 <= 1. Thus the valid interval is [0,(sqrt(5)-1)/2].
Example 2
weight = 0return = 1.0The probabilities are q,0,1-q, so the valid range is [0,1].
Example 3
weight = 2return = 0.5At q=0.5, the probabilities are 0.5,0.5,0. Larger values make the final probability negative.
Example 4
weight = 6return = 0.3333333333333333The upper endpoint is 1/3 because 1/3+6*(1/3)^2=1.
Constraints
0 <= weight <= 1000000.- Zero probabilities are allowed, so both interval endpoints are included.
- Return the upper endpoint as a
double.
More IMC Trading Phone Screen questions
- Election District Budget Allocation AnalysisPHONE SCREEN · Seen Aug 2026
- Uniform Variables: Smaller Below Larger SquaredPHONE SCREEN · Seen Mar 2026
- Combination Sum with Unlimited ReusePHONE 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