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.
publicstaticintactivityNotifications(List<int>expenditure,intd){vartotalNotifications=0;int[]frequency=newint[201];// Create a frequency array.if(expenditure.Count>d){for(inti=0;i<d;++i){frequency[expenditure[i]]++;}for(inti=d;i<expenditure.Count;i++){varmedian=GetMedian(frequency,d);if(expenditure[i]>=2*median){totalNotifications++;}frequency[expenditure[i-d]]--;// Remove element from the frequency.frequency[expenditure[i]]++;// Add element to the frequency.}}returntotalNotifications;}publicstaticdoubleGetMedian(int[]frequency,intd){varsum=0;doublemedian=0;if(d%2==1){varmid=d/2;for(inti=0;i<frequency.Length;++i){sum+=frequency[i];if(sum>mid){median=i;break;}}}else{varmid1=d/2-1;varmid2=d/2;intmedian1=-1,median2=-1;for(inti=0;i<frequency.Length;++i){sum+=frequency[i];if(sum>mid1&&median1==-1){median1=i;}if(sum>mid2){median2=i;median=(median1+median2)/2.0;break;}}}returnmedian;}
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 →
C#