Find a Black-Box Convex Function Minimum
Company: Uber
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency in zero-order optimization and algorithm design, focusing on reasoning about convexity and unimodality when only function evaluations are available.
Read the full Uber Machine Learning Engineer interview experience this question came from
Part 1: Approximate Minimum of a Continuous Unimodal Function
Constraints
- expr is a valid Python expression using x, abs, and functions/constants from the math module such as exp, sqrt, sin, pi, and e.
- F(x) is defined for every x in the search interval.
- F(x) is convex or unimodal on [min(a, b), max(a, b)].
- 0 < epsilon <= 1
- -1000000 <= a, b <= 1000000
Examples
Input: ('(x-2.5)**2 + 1', 0.0, 5.0, 1e-6)
Expected Output: 2.5
Explanation: A simple convex parabola with minimum at x = 2.5.
Input: ('abs(x-1.2)', 0.0, 4.0, 1e-6)
Expected Output: 1.2
Explanation: The function is convex but not differentiable at the minimum.
Hints
- For a unimodal function, comparing F at two interior points lets you discard one side of the interval.
- Keep shrinking the interval until its width is at most epsilon, then use the remaining interval to form your answer.
Part 2: Minimum of a Discrete Unimodal Function on an Integer Interval
Constraints
- expr is a valid Python expression using x, abs, and functions/constants from the math module.
- a and b are integers.
- F(x) is defined for every integer x in [min(a, b), max(a, b)].
- F(x) is discrete convex or unimodal on the integer interval.
- -1000000000 <= a, b <= 1000000000
Examples
Input: ('(x-4)**2', 0, 10)
Expected Output: 4
Explanation: A standard convex parabola with a unique minimum.
Input: ('abs(x-2)', -5, 5)
Expected Output: 2
Explanation: The minimum occurs at the cusp.
Hints
- On integers, comparing F(mid) and F(mid + 1) is enough to tell which side still contains a minimum.
- If F(mid) == F(mid + 1), keep the left half if you want the smallest minimizing index.