You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi &lt; xj for all 1 &lt;= i &lt; j &lt;= points.length. You are also given an integer k.

Return the maximum value of the equation yi + yj + |xi - xj| where |xi - xj| &lt;= k and 1 &lt;= i &lt; j &lt;= points.length.

It is guaranteed that there exists at least one pair of points that satisfy the constraint |xi - xj| &lt;= k.

&nbsp;
Example 1:

Input: points = [[1,3],[2,0],[5,10],[6,-10]], k = 1
Output: 4
Explanation: The first two points satisfy the condition |xi - xj| &lt;= 1 and if we calculate the equation we get 3 + 0 + |1 - 2| = 4. Third and fourth points also satisfy the condition and give a value of 10 + -10 + |5 - 6| = 1.
No other pairs satisfy the condition, so we return the max of 4 and 1.


Example 2:

Input: points = [[0,0],[3,0],[9,2]], k = 3
Output: 3
Explanation: Only the first two points have an absolute difference of 3 or less in the x-values, and give the value of 0 + 0 + |0 - 3| = 3.


&nbsp;
Constraints:


	2 &lt;= points.length &lt;= 105
	points[i].length == 2
	-108 &lt;= xi, yi &lt;= 108
	0 &lt;= k &lt;= 2 * 108
	xi &lt; xj for all 1 &lt;= i &lt; j &lt;= points.length
	xi form a strictly increasing sequence.


class Solution:
    def findMaxValueOfEquation(self, points: List[List[int]], k: int) -> int:
        """
            Eqn is: yi + yj + |xi - xj|
            Since points is sorted by x values, 
                therefore, xj will always be greater than xi
                therefore xi - xj will always be negative
            So the above eqn can be rewritten as,
                (yj+xj) + (yi-xi)
            Now the problem boils down to finding maximum in sliding window of k size.
            (https://leetcode.com/problems/sliding-window-maximum/discuss/1911533/Python-or-Dequeue-or-Sliding-Window-or-Simple-Solution)
        """
        queue = deque()
        maxVal = -sys.maxsize
        for x,y in points:
            while queue and abs(queue[0][0] - x) > k:
                queue.popleft()
            
            if queue:
                maxVal = max(maxVal, y+x+queue[0][1])
            
            while queue and queue[-1][1] <= y-x:
                queue.pop()
            
            queue.append((x, y-x))
            
        return maxVal
class Solution {
    public int findMaxValueOfEquation(int[][] points, int k) {
        int ans=Integer.MIN_VALUE;
        int i=0;
        int f=1;
        while(i < points.length) {
            if(f<i+1)
                f=i+1;
            for (int j = f; j <= points.length-1; j++) {
                if(points[j][0]>(points[i][0]+k))
                    break;
                if((points[i][1]+points[j][1]+points[j][0]-points[i][0])>ans){
                    ans=points[i][1]+points[j][1]+points[j][0]-points[i][0];
                    f=j-1;
                }
            }
            i++;
        }
        return ans;
    }
}
class Solution {
public:
    int findMaxValueOfEquation(vector<vector<int>>& points, int k) {
        deque<pair<int, int>> dq;
        int res = -INT_MAX;
        for(auto point: points){
            while(!dq.empty() && point[0]-dq.front().second>k){
                dq.pop_front();
            }
            if(!dq.empty()){
                res = max(res, dq.front().first+point[0]+point[1]);
            }
            while(!dq.empty() && point[1]-point[0]>=dq.back().first){
                dq.pop_back();
            }
            dq.push_back({point[1]-point[0], point[0]});
        }
        return res;
    }
};
var findMaxValueOfEquation = function(points, k) {
    let result = -Infinity;
    let queue = [];
    for(let point of points) {
        while(queue.length && point[0] - queue[0][1] > k) {
            queue.shift();
        }
        if(queue.length) {
            result = Math.max(result, queue[0][0] + point[1] + point[0]);
        }
        while(queue.length && point[1] - point[0] > queue[queue.length - 1][0]) {
            queue.pop();
        }
        queue.push([point[1] - point[0], point[0]]);
    }
    return result;
};
Max Value of Equation