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.
Fraudulent Activity Notifications
Fraudulent Activity Notifications
Sort by
recency
|
1166 Discussions
|
Please Login in order to post a comment
Use binary search ranther than full sort of the trailing is the key point to improve performance.
Can anyone help to check where i miss. 1 test case is repeatedly failing due to time limit exceed
int activityNotifications(vector expenditure, int d) { vector med; int i,j,median,pos,s=expenditure.size(),c=0,c2=0; float m; median=d/2; for(i=0;i=d) { if(d%2==0) m=(float)(med[median]+med[median-1])/2.0; else m=(float)med[median]; if(expenditure[i]>=2*m) c2++;
auto ind=find(med.begin(),med.end(),expenditure[c]); med.erase(ind); c++; } if(med.empty()||med[0]>expenditure[i]) med.insert(med.begin(),expenditure[i]); else if(med[med.size()-1] } return c2; }
C#: I went with a counting sort solution. We know that each day is <= 0 and >= 200. So we generate a dictionary and create a key for each possible value. We start by adding the first d values to the dictionary. We never finish the sort, since we only care about finding the median. We track what the minimum number in our dictionary to lower the number of iterations when trying to find each median.
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to five a star :) )
Only passing 3/8 Tests, rest fail due to time limit exceeded. Can someone help me identify where in my code I could improve. I am aware I could use the sort method, instead of my sortArray other than that how would I improve this code to pass the rest of the tests. Thank you