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