You are viewing a single comment's thread. Return to all comments →
use BS in sorted copied vector by deleting the searched value;
int minimumLoss(vector<long> price) { long n=price.size(); int mini=INT_MAX; vector <long> prs; for(int i=0;i<n;i++){ prs.push_back(price[i]); } sort(prs.begin(),prs.end()); for(int i=0;i<n;i++){ int l=1; int mid; int h=prs.size()-1; while(l<=h){ mid=(l+h)/2; if(price[i]==prs[mid]){ long x=prs[mid]-prs[mid-1]; if(mini>x){ mini=x; } prs.erase(prs.begin()+mid); break; } else if(price[i]<prs[mid]){ h=mid-1; } else{ l=mid+1; } } } return mini; }
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Loss
You are viewing a single comment's thread. Return to all comments →
use BS in sorted copied vector by deleting the searched value;