Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Max Value of Equation

XPChallenge Points: 30
levelLevel: Hard

You are given an array points containing the coordinates of points on a 2D plane, sorted by their x-values, where
points[i] = [xi, yi] and it is guaranteed that xi < xj for all 1 ≤ i < j ≤ points.length.

You are also given an integer k.

Your task is to return the maximum value of the equation:

yi+yj+xixjyi + yj + |xi - xj|

subject to the constraint:

xixjk|xi - xj| ≤ k

and 1i<jpoints.length1 ≤ i < j ≤ points.length.

It is guaranteed that at least one pair of points satisfies the constraint.

Example 1:

Input: points = [[1,3],[2,0],[5,10],[6,-10]], k = 1

Output: 4

Explanation:

The first two points satisfy |1 − 2| ≤ 1 → equation = 3 + 0 + |1 − 2| = 4 The third and fourth points also satisfy |5 − 6| ≤ 1 → equation = 10 + (−10) + |5 − 6| = 1 No other pairs satisfy the condition. Hence, the maximum value is 4.

Example 2:

Input: points = [[0,0],[3,0],[9,2]], k = 3

Output: 3

Explanation:

Only the first two points satisfy |0 − 3| ≤ 3. Equation value = 0 + 0 + |0 − 3| = 3. Therefore, the output is 3.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result