Valid Range of a Three-Outcome Probability Parameter
Problem statement
Three mutually exclusive outcomes have probabilities 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.
For this exercise, assume the nonnegative integer weight is an input, generalizing the reported coefficient 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. No portfolio payoffs or trading decisions form part of this probability-range task.
Function
maximumValidQ(weight: int) → doubleExamples
Example 1
weight = 1return = 0.6180339887498949Nonnegativity requires q >= 0 and q+q^2 <= 1. Thus the reported 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
- For this exercise, assume
0 <= weight <= 1000000. - Zero probabilities are allowed, so both interval endpoints are included.
- Return the upper endpoint as a
double.