129. Max Value of Equation

HardArrayArray

Given points sorted by x and integer k, return the maximum value of yi+yj+|xi-xj| over all pairs i<j with |xi-xj|<=k. Input: 'points_json, k'.

Input: 'points_json, k'.

Output: Integer — max equation value.

Examples

Example 1
Input: [[1,3],[2,0],[5,10],[6,-10]], 1
Output: 4
Explanation: Points (1,3),(2,0): 3+0+1=4.
Example 2
Input: [[0,0],[3,0],[9,2]], 3
Output: 3
Explanation: Best valid pair.

Constraints

Asked by

Google
Solve this problem in the editor →