I don’t know why you would assume that ballX and playerX are always ordered the same way but I interverted ballX and playerX in testcase 2 so there should be no surprise now.

Thanks, inverting them is fine, but dropping it as a surprise during validation is not. Those who don’t have access to the contribution won’t understand what’s going on.

LOL - after seeing brute-force is not viable because of the huge range of possibe solutions, I tried to solve this on paper with calculus but failed miserably when the equation became of degree 4… Then my thoughts were around gradient descent and I started to feel dispair.
But in the end it turned out that this is much simpler than that, as f() has no other local minimums.
Using so much zoom last year should have given the idea earlier…

If you consider T(x) the time spent to reach the ball depending on the x you choose, then the derivative T’ is not too hard to calculate.
And then whatever formula you get, even if you have squareroots, powers etc, you just have to find its zero so even if you cannot solve the equation for exact value, any method that gives a good approximation of a zero would be fine (dichotomy, newton, etc).

I am not sure about that, x range in the last test case is 20M integers.

Sure, but then it is no longer the analytic solution on paper I originally aimed for…

Anyhow, a simple ‘zoom-in’ type of search is simpler than any newton and also works here as the time() seems to be monotone decreasing to the global minimum, then monotone increasing.
My post was meant more about the thought process than about the solution.