@StefanPochmann Hey Stefan, fantastic!

I am still confused about the explanation on choosing which "window is better".

For the 2 windows : arr[i:i+k] and arr[(i+1):(i+1)+k], let we define

d1 = max(abs(target - arr[i]), abs(target - arr[i+k-1]))

d2 = max(abs(target - arr[i+1]), abs(target - arr[i+k]))

I think the way to choose a "better window" is to choose the minimum (d1, d2), i.e the window with maximum distance towards target should be minimum. But this is wrong.

Could you explain more about your solution on how to decide "which window is better"?

Thanks!

I always learn a lot from you :)