Fraudulent Activity Notifications

  • + 0 comments
    #include <bits/stdc++.h>
    
    using namespace std;
    
    vector<string> split_string(string);
    double getMedian(vector<int> occur, int elements);
    // Runs in O(n*d)
    int activityNotifications(vector<int> exp, int d) {
        
        int n;
        int count;
        int old_exp;
        vector<int>  occur(201);
        queue <int>  transaction_queue;
        double median;//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(int i =0; i< d;i++)
            occur[exp[i]]++;
        
        
        for(int i =0; i< d;i++)
            transaction_queue.push(exp[i]);
        
        
        for(int i = 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]]++;
        }
        
        
        return count;
    }
    
    double getMedian(vector<int> occur, int elements){
        
        int i;
        int j;
        bool isEven;
        int count;
        double median;
        
        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);
        }
        
        return median;
    }
    
        return splits;
    }