how to do this problem?? Sir I also want to tell you that I have a problem in sovling co-ordinate related sums.Can u someway help me out regarding this matter to??
Equations leetcode
this is question you have to maximize the value of the equation yi + yj + |xi - xj|
where |xi - xj| <= k
yi + yj + |xi - xj|
= (yi -xi) + (yj + xj)
because xj > xi
for a given j xj+yj remains constant so find max value of (yi - xi)
for that you can use priority queue
Reference Code
int findMaxValueOfEquation(vector<vector<int>>& points, int k) {
priority_queue<pair<int,int>> q;
int res = INT_MIN;
for(auto& p:points){
int u = p[0], v = p[1];
while(!q.empty()){
auto [d, x] = q.top();
if(u-x <= k){
res = max(res, u+v+d);
break;
}
else q.pop();
}
q.push(pair{v-u, u});
}
return res;
}