Convex Function Minimization
Reported by candidates from Uber's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Uber OA reported in May 2026 hands you a quadratic and tells you to minimize it on an interval. Sounds like a trick, because it is one. The statement dresses it up as a black-box function where ternary search is the intended approach, but the input is just A, B, C, left, right per query with A > 0. You read q lines, return one rounded x per line. It's a short problem if you spot the shortcut and a slow one if you don't. If you blank mid-assessment, StealthCoder is the invisible hedge sitting on your screen.
The problem
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 solveConvexFunctionMinimization(input: String) → String[] 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. Examples Example 1 input = "3\n1 -4 7 0 10\n1 2 1 0 5\n2 -8 1 3 10" return = ["2.000000","0.000000","3.000000"] The unconstrained minimizers are 2, -1, and 2 respectively; the second and third are clamped to their intervals. Constraints Each query describes a convex quadratic with A > 0. Return answers rounded to exactly six decimal places.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: F(x) = A*x^2 + B*x + C with A > 0 has its vertex at x = -B / (2A). Clamp that to [left, right] and you're done. No ternary search needed, though ternary search on the interval also works and is what the prompt hints at. Closed form is faster and avoids precision drift. Pitfalls: forgetting to clamp, which breaks the second and third examples (-1 becomes 0, and 2 becomes 3). Also watch formatting. Output must have exactly six digits after the decimal point, so use fixed formatting, and watch for negative zero printing as -0.000000. Parse the first line as q, then split each following line into five numbers. Use floating point division, not integer division. If the vertex math or the formatting slips on the live OA, StealthCoder can give you a working solution without anyone seeing it.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Convex Function Minimization cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Uber's OA.
Uber reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Convex Function Minimization FAQ
What's the actual trick in the Uber Convex Function Minimization problem?+
The function is a quadratic with A > 0, so the minimizer is the vertex at x = -B / (2A). Clamp it into [left, right] and format to six decimals. Ternary search is the advertised approach, but the closed form is simpler and exact.
Should I use ternary search or the formula?+
Use the formula. It's O(1) per query and has no iteration count to tune. Ternary search works if you run enough iterations, around 100, but it adds precision risk for no gain. Mention ternary search only if the interviewer wants the general black-box approach.
Where do people lose points on this one?+
Mostly clamping and output format. If the vertex falls outside the interval you must return the nearest endpoint. Also print exactly six decimals, and guard against negative zero showing as -0.000000 when the answer is a tiny negative number rounding to zero.
How hard is this problem really?+
Easy if you recognize the vertex formula, easy-medium if you go the ternary route. There's no data structure or tricky algorithm. The difficulty is mostly input parsing, float handling, and exact formatting of the returned strings.
How do I prepare for this in 48 hours?+
Write the vertex plus clamp solution once and test it against the three sample queries. Then write a ternary search version as a backup. Practice fixed-decimal formatting in your language so the six-digit output is automatic when the assessment starts.