Fraudulent Activity Notifications

  • + 4 comments
    int activityNotifications(vector<int> expenditure, int d) {
    int cnt=0;
    int k=int(d/2);
    vector<int>::iterator it;
    int med;
    for(it=expenditure.begin();it<expenditure.end()-d;it++)
    {
        vector<int> a(it,it+d);
        sort(a.begin(),a.end());
        if (d % 2 != 0) 
        {
          if (*(it + d) >= 2 * (a[k]))
          {
            cnt++;
          }
        }
         else
         {
          med = (((a[k] + a[k - 1]) / 2) + 1) * 2;
          if (*(it + d) >=med) {
            cnt++;
          }
         }
    }
    return cnt;
    }
    

    I am getting timed out error. Can you help me out?