Untitled
unknown
plain_text
a year ago
2.3 kB
19
Indexable
def find_fraudulent_merchants_part1(non_fraud_codes, fraud_codes, mcc_thresholds, merchant_mcc_map, min_charges, charges):
non_fraud_codes = set(non_fraud_codes.split(','))
fraud_codes = set(fraud_codes.split(','))
mcc_dict = {}
for mcc in mcc_thresholds:
code, threshold = mcc.split(',')
mcc_dict[code] = int(threshold)
merchant_dict = {}
for merchant in merchant_mcc_map:
account, mcc = merchant.split(',')
merchant_dict[account] = mcc
transaction_count = {}
fraudulent_count = {}
for charge in charges:
_, charge_id, account_id, amount, code = charge.split(',')
if account_id not in transaction_count:
transaction_count[account_id] = 0
fraudulent_count[account_id] = 0
transaction_count[account_id] += 1
if code in fraud_codes:
fraudulent_count[account_id] += 1
min_charges = int(min_charges)
fraudulent_merchants = []
for account_id in merchant_dict:
if transaction_count[account_id] >= min_charges:
mcc = merchant_dict[account_id]
threshold = mcc_dict.get(mcc, float('inf'))
if fraudulent_count[account_id] >= threshold:
fraudulent_merchants.append(account_id)
return ','.join(sorted(fraudulent_merchants))
# Test case for Part 1
non_fraud_codes_1 = "approved,invalid_pin,expired_card"
fraud_codes_1 = "do_not_honor,stolen_card,lost_card"
mcc_thresholds_1 = [
"retail,5",
"airline,2",
"restaurant,10",
"venue,3"
]
merchant_mcc_map_1 = [
"acct_1,airline",
"acct_2,venue",
"acct_3,retail"
]
min_charges_1 = "0"
charges_1 = [
"CHARGE,ch_1,acct_1,100,do_not_honor",
"CHARGE,ch_2,acct_1,200,approved",
"CHARGE,ch_3,acct_1,300,do_not_honor",
"CHARGE,ch_4,acct_2,100,lost_card",
"CHARGE,ch_5,acct_2,200,lost_card",
"CHARGE,ch_6,acct_2,300,lost_card",
"CHARGE,ch_7,acct_3,100,lost_card",
"CHARGE,ch_8,acct_3,200,stolen_card",
"CHARGE,ch_9,acct_3,100,approved"
]
# Running Part 1 test case
result_part_1 = find_fraudulent_merchants_part1(non_fraud_codes_1, fraud_codes_1, mcc_thresholds_1, merchant_mcc_map_1, min_charges_1, charges_1)
print(f"Part 1 Result: {result_part_1}") # Expected: acct_1,acct_2
Editor is loading...
Leave a Comment