1499. Max Value of Equation Hard

@problem@discussion
#Array#Queue#Sliding Window#Heap (Priority Queue)#Monotonic Queue



1/**
2 * [1499] Max Value of Equation
3 *
4 * 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 < xj for all 1 <= i < j <= points.length. You are also given an integer k.
5 * Return the maximum value of the equation yi + yj + |xi - xj| where |xi - xj| <= k and 1 <= i < j <= points.length.
6 * It is guaranteed that there exists at least one pair of points that satisfy the constraint |xi - xj| <= k.
7 *  
8 * Example 1:
9 * 
10 * Input: points = [[1,3],[2,0],[5,10],[6,-10]], k = 1
11 * Output: 4
12 * Explanation: The first two points satisfy the condition |xi - xj| <= 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.
13 * No other pairs satisfy the condition, so we return the max of 4 and 1.
14 * 
15 * Example 2:
16 * 
17 * Input: points = [[0,0],[3,0],[9,2]], k = 3
18 * Output: 3
19 * 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.
20 * 
21 *  
22 * Constraints:
23 * 
24 * 	2 <= points.length <= 10^5
25 * 	points[i].length == 2
26 * 	-10^8 <= xi, yi <= 10^8
27 * 	0 <= k <= 2 * 10^8
28 * 	xi < xj for all 1 <= i < j <= points.length
29 * 	xi form a strictly increasing sequence.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/max-value-of-equation/
35// discuss: https://leetcode.com/problems/max-value-of-equation/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn find_max_value_of_equation(points: Vec<Vec<i32>>, k: i32) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_1499() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.