FastPrepFastPrep
Problem Brief

Convex Function Minimization

FULLTIMEPHONE SCREEN
See Uber online assessment and hiring insights

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.

Function Description

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

Input
input = "3\n1 -4 7 0 10\n1 2 1 0 5\n2 -8 1 3 10"
Output
["2.000000","0.000000","3.000000"]
Explanation

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.

public String[] solveConvexFunctionMinimization(String input) {
    // write your code here
}
Input

input

"3\n1 -4 7 0 10\n1 2 1 0 5\n2 -8 1 3 10"

Output

["2.000000", "0.000000", "3.000000"]

Sign in to submit your solution.