1521. Find a Value of a Mysterious Function Closest to Target

https://leetcode.com/problems/find-a-value-of-a-mysterious-function-closest-to-target

Description

Winston was given the above mysterious function func. He has an integer array arr and an integer target and he wants to find the values l and r that make the value |func(arr, l, r) - target| minimum possible.

Return the minimum possible value of |func(arr, l, r) - target|.

Notice that func should be called with the values l and r where 0 <= l, r < arr.length.

Example 1:

Example 2:

Example 3:

Constraints:

  • 1 <= arr.length <= 105

  • 1 <= arr[i] <= 106

  • 0 <= target <= 107

ac

Last updated

Was this helpful?