You are viewing a single comment's thread. Return to all comments →
Simple C++ solution:
double calcMedian(vector v, int d) { if(d % 2 == 1) return v[d/2]; else return (v[d/2] + v[d/2 - 1])/2.0; }
int activityNotifications(vector expenditure, int d) { //multiset s; vector v; double median = 0; int notifications = 0;
int n = expenditure.size(); if(n <= d) return 0; for(int i=0; i<d; i++) { //s.insert(expenditure[i]); v.push_back(expenditure[i]); } sort(v.begin(), v.end()); for(int i=d; i<n; i++) { median = calcMedian(v, d); if(expenditure[i] >= (2*median)) notifications++; v.erase(find(v.begin(), v.end(),expenditure[i-d])); //binary search auto it = lower_bound(v.begin(), v.end(), expenditure[i]); v.insert(it, expenditure[i]); } return notifications;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Fraudulent Activity Notifications
You are viewing a single comment's thread. Return to all comments →
Simple C++ solution:
double calcMedian(vector v, int d) { if(d % 2 == 1) return v[d/2]; else return (v[d/2] + v[d/2 - 1])/2.0; }
int activityNotifications(vector expenditure, int d) { //multiset s; vector v; double median = 0; int notifications = 0;
}