Class Solution
java.lang.Object
g1401_1500.s1499_max_value_of_equation.Solution
1499 - Max Value of Equation.<p>Hard</p>
<p>You are given an array <code>points</code> containing the coordinates of points on a 2D plane, sorted by the x-values, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> such that <code>x<sub>i</sub> < x<sub>j</sub></code> for all <code>1 <= i < j <= points.length</code>. You are also given an integer <code>k</code>.</p>
<p>Return <em>the maximum value of the equation</em> <code>y<sub>i</sub> + y<sub>j</sub> + |x<sub>i</sub> - x<sub>j</sub>|</code> where <code>|x<sub>i</sub> - x<sub>j</sub>| <= k</code> and <code>1 <= i < j <= points.length</code>.</p>
<p>It is guaranteed that there exists at least one pair of points that satisfy the constraint <code>|x<sub>i</sub> - x<sub>j</sub>| <= k</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> points = [[1,3],[2,0],[5,10],[6,-10]], k = 1</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> The first two points satisfy the condition |x<sub>i</sub> - x<sub>j</sub>| <= 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.</p>
<p>No other pairs satisfy the condition, so we return the max of 4 and 1.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> points = [[0,0],[3,0],[9,2]], k = 3</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> 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.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= points.length <= 10<sup>5</sup></code></li>
<li><code>points[i].length == 2</code></li>
<li><code>-10<sup>8</sup> <= x<sub>i</sub>, y<sub>i</sub> <= 10<sup>8</sup></code></li>
<li><code>0 <= k <= 2 * 10<sup>8</sup></code></li>
<li><code>x<sub>i</sub> < x<sub>j</sub></code> for all <code>1 <= i < j <= points.length</code></li>
<li><code>x<sub>i</sub></code> form a strictly increasing sequence.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findMaxValueOfEquation
public int findMaxValueOfEquation(int[][] points, int k)
-