1499. Max Value of Equation
Return maximum value of the equation: yi + yj + |xi - xj| where |xi - xj| <= k
how find max (yi + yj + xi - xj) , 1 <= i < j <= points.length, so xi - xj is positive
fix j, is new incoming value yj + xj = max (-xi + yi)
think of mono queue, main a decreasing mono queue
decreasing mono queue 分兩個 case, 但 queue 還是放 index
pop last - in here, is (-xi + yi) ≤ nums[i]
pop first - |xi-xj| ≤ k
所以隊首都會是最大的
T: O(n)
S: O(n)
Previous1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit - sliding win +heapNextmono stack
Last updated