Convex Function Minimization
Complete the function below. The function receives the full standard input as a single string and returns the exact standard output lines.
Problem
You are given access to a black-box convex or unimodal function on a closed interval [a, b]. In this text version, the black-box function is represented as a quadratic F(x) = ax^2 + bx + c, and you must find the approximate x in the search interval that minimizes F(x).
For each query, output the minimizing x rounded to exactly six digits after the decimal point. If the unconstrained minimizer lies outside the interval, clamp it to the nearest endpoint.
This models the interview task where the only allowed operation is evaluating the black-box function; ternary search is the intended general approach.
Complete solveConvexFunctionMinimization. It has one parameter, String input. The first line is q. Each of the next q lines contains A B C left right for F(x)=A*x*x+B*x+C on interval [left, right]. Return one rounded minimizer per query.
1Example 1
The unconstrained minimizers are 2, -1, and 2 respectively; the second and third are clamped to their intervals.
Constraints
Limits and guarantees your solution can rely on.
Each query describes a convex quadratic with A > 0.
Return answers rounded to exactly six decimal places.