Tap here to switch tabs
Problem
Submissions

Problem: Max Value of Equation

Try to solve the Max Value of Equation problem.

Statement

You are given an array points containing the coordinates of points on a 2D plane, where points[i] =[xi,yi]= [x_i, y_i] is sorted by xx values in strictly increasing order, and an integer k.

Find and return the maximum value of the equation yi+yj+∣xi−xj∣y_i + y_j + |x_i - x_j| such that ∣xi−xj∣≤|x_i - x_j| \leq k and 1≤i<j≤1 \leq i < j \leq points.length.

It is guaranteed that there exists at least one pair of points that satisfies the condition ∣xi−xj∣≤|x_i - x_j| \leq k.

Constraints:

  • 2≤2 \leq points.length ≤105\leq 10^5

  • points[i].length =2= 2

  • −108≤xi,yi≤108-10^8 \leq x_i, y_i \leq 10^8

  • 0≤0 \leq k ≤2×108\leq 2 \times 10^8

  • xi<xjx_i < x_j for all 1≤i<j≤1 \leq i < j \leq points.length

  • xix_i form a strictly increasing sequence.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Max Value of Equation

Try to solve the Max Value of Equation problem.

Statement

You are given an array points containing the coordinates of points on a 2D plane, where points[i] =[xi,yi]= [x_i, y_i] is sorted by xx values in strictly increasing order, and an integer k.

Find and return the maximum value of the equation yi+yj+∣xi−xj∣y_i + y_j + |x_i - x_j| such that ∣xi−xj∣≤|x_i - x_j| \leq k and 1≤i<j≤1 \leq i < j \leq points.length.

It is guaranteed that there exists at least one pair of points that satisfies the condition ∣xi−xj∣≤|x_i - x_j| \leq k.

Constraints:

  • 2≤2 \leq points.length ≤105\leq 10^5

  • points[i].length =2= 2

  • −108≤xi,yi≤108-10^8 \leq x_i, y_i \leq 10^8

  • 0≤0 \leq k ≤2×108\leq 2 \times 10^8

  • xi<xjx_i < x_j for all 1≤i<j≤1 \leq i < j \leq points.length

  • xix_i form a strictly increasing sequence.