glad that i understand the problem writes the 150 lines code by me fully in 1 hr just a glag value remains that why not completed but question was craxy and experience is mind blowing
Q.Statment(rough): we have given three vector of string named transaction,ruleList and merchant
the format of each of three string vector like
transaction:comma separated merchant,amount,customer,time; // time is in hr from 0 to 23
ruleList:comma separated min_threshold,*factor,+factor,penalty;
merchantList: comma separated merchant name and merchant base score .
so basically we have to return a vector of string fraud_score for each merchant exist in merchant_list the output string format is comma seprated <merchant,fraudscorre>
keep initial fraud score = curr score of merchants by merchant_List;
Rules:
1 --> if (amount > min_threshold) then currfact should multipley by multiplicative factor
2 --> if(the transaction between merchant and customer >=3)
then on third transition add additive for 1st and second
and on >3 add curr additve factor(+factor);
3 --> if(the transaction between merchant and customer >=3 in the same hour )
if(hr is betwwen 12 to 17 inclusive }
for 3 rd transaction ->add penalty for 1st and second transaction
for >3 transaction add their penalty in curr score;
if(hr is betwwen 9 to 11 or 18 to 21 )
subtract current penalty from curr score
my approach
stuff used and for
1 maps
-map<pairpair<string,string>,int>,int> for for saving 1st and second transaction penalty hour wise ;
mp[{{merchant,customer},hr}]+=penalty;
map<pairpair<string,string>,int>,int> for for saving freq of hour wise ;
mp[{{merchant,customer},hr}]++;
map<string,int> for saving and updating merchants score....
-map<{string,string},int> for counting frequency
simple logic used
for (int i=0;i<n;i++)
{
extracted all things by stringstream with ',' separated;
updated logic
}
so for curr=1 we have to add the additive and penalty so for this i used to flag f1 and f2 where if f1=0 it mean 1 or 2 and second freq is coming add additive and penalty
so for curr=2 we have to add the additive and penalty so for this i used to flag f1 and f2 where if f1=0 it mean 1 or 2 and second freq is coming add additive and penalty and then make both flags 1
if curr>=3 and flag then condition written
everything is perfect i didnt updated the f2 only .