We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>usingnamespacestd;vector<string>split_string(string);doublegetMedian(vector<int>occur,intelements);// Runs in O(n*d)intactivityNotifications(vector<int>exp,intd){intn;intcount;intold_exp;vector<int>occur(201);queue<int>transaction_queue;doublemedian;//i have some confusion in the code if there is a function that is activityNotificatiion give output of two function & logic of two function then what's "give the error" here the code of two logic in two different function.count=0;n=exp.size();for(inti=0;i<d;i++)occur[exp[i]]++;for(inti=0;i<d;i++)transaction_queue.push(exp[i]);for(inti=d;i<n;i++){median=getMedian(occur,d);if(exp[i]>=2.0*median){count++;}old_exp=transaction_queue.front();occur[old_exp]--;transaction_queue.pop();transaction_queue.push(exp[i]);occur[exp[i]]++;}returncount;}doublegetMedian(vector<int>occur,intelements){inti;intj;boolisEven;intcount;doublemedian;i=0;isEven=(elements%2==0);count=0;if(isEven){count=elements/2;while(count>0){count-=occur[i];i++;}i--;if(count<0){median=(double)i;}else{j=i+1;while(occur[j]==0){j++;}median=(double)(i+j)/(2);}}else{count=floor(elements/2);while(count>=0){count-=occur[i];i++;}i--;median=(double)(i);}returnmedian;}returnsplits;}
Cookie support is required to access HackerRank
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 →