# c ++ – HackerRank: notification of fraudulent activity I wanted to get constructive feedback on my solution to HackerRank's fraudulent activity notification problem:

HackerLand National Bank has a simple policy to warn customers of the possibility of fraudulent activity on their accounts. If the amount spent by a customer on a given day is greater than or equal to 2 × the median client spend for a number of days remaining, it sends the client a notification of potential fraud. The bank does not send any notification to the client until it has at least the last number of transaction data from previous days.

Given the number of days of flight re and total daily expenses of a client for a period of not days, find and print the number of times that the customer will receive a notification for all not days.

For example, re = 3 and expenses = [10, 20, 30, 40, 50]. The first three days, they only collect data on expenditures. On day 4, we have leakage expenses of [10, 20, 30]. The median is 20 and the expense of the day is 40. Because 40 ≥ 2 × 20, there will be a notice. The next day, our follow-up expenses are [20, 30, 40] and expenses are 50. It's less than 2 × 30, no notice will be sent. During the period, a notice was sent.

### Input format

The first line contains two integers separated by spaces not and re, the number of days of transaction data, and the number of data from the last days used to calculate median expenditures.
The second line contains not non-negative integers separated by spaces where each integer I denotes spent[[[[I].

### constraints

• 1 ≤ not ≤ 2 × 105
• 1 ≤ renot
• 0 ≤ spent[[[[I]≤ 200

I think I have the opportunity to increase the waiting time for some problems.
How would you solve it without having a kind? Sorting during insertion is much more complex …

``````#understand
#understand

using namespace std;

vector string_switch (string);

// Complete the activityNotifications function below.
int activityNotifications (vector expenditure, int d) {
int result = 0;
int dq_idx = 0;
median double = 0;
vector dq;
for (int i = 0; i< expenditure.size()-1; i++){
if (dq_idx >= dq.size ()) {
dq.push_back (expenses[i])
} other {
dq.at (dq_idx) = expense[i];
}
dq_idx = (dq_idx + 1)% d;

if (dq.size ()> = d) {
sort (dq.begin (), dq.end ());
if (d% 2 == 0) {
median = 2 * (dq[d/2 -1 ] + dq[(d/2)]) / 2;
} other {
median = 2 * dq[d%2];
}
if ((float)) expenses[i+1] > = median) {
result ++;
}
}
}
return the result;
}

int main ()
{
ofstream fout (getenv ("OUTPUT_PATH"));

string nd_temp;
getline (cin, nd_temp);

vector nd = split_string (nd_temp);

int n = stoi (nd)

int d = stoi (nd)

string expenditure_temp_temp;
getline (cin, temp_temp_cost);

vector expenditure_temp = split_string (temp_temp_cost);

vector expenditure (n);

for (int i = 0; i <n; i ++) {
int expenses_item = stoi (expenses_temp[i])

spent[i] = expenditure_item;
}

int result = activityNotifications (expenses, d);

fout << result << " n";

fout.close ();

returns 0;
}

vector split_string (string input_string) {
string :: iterator new_end = unique (input_string.begin (), input_string.end (), [] (const char & x, char const & y) {
returns x == y and x == & # 39 ;;
});

input_string.erase (new_end, input_string.end ());

while (input_string[input_string.length() - 1] == & # 39;) {
input_string.pop_back ();
}

vector divides itself;
character delimiter = & # 39;

size_t i = 0;
size_t pos = input_string.find (delimiter);

while (pos! = string :: npos) {
splits.push_back (substring_string (i, pos - i));

i = pos + 1;
pos = input_string.find (delimiter, i);
}

splits.push_back (input_string.substr (i, min (pos, input_string.length ()) - i + 1));

returns splits;
}
`````` Posted on