Risky Fraud Ring
Problem statement
Stripe Fraud Ring Tasks
This problem is Task 3 of 3 in the Stripe fraud-ring sequence.
- Task 1: Directly Linked Users
- Task 2: Fraud Ring Size
- Task 3: Risky Fraud Ring (current)
Not every connected cluster is malicious. Each transaction includes a risk score, and a fraud ring should be blocked only when its average risk is high.
Each transaction log entry is formatted as user_id,device_id,credit_card,risk_score. Users are connected by shared devices or credit cards. The ring for a target user is the connected component containing that user.
A user with risk score 0 is trusted. Trusted users still keep the graph connected, but they are excluded from both the sum and count when computing the average risk score.
Return true if the average risk score of non-trusted users in the target ring is strictly greater than 75; otherwise return false.
Input
transactions: transaction rows formatted asuser_id,device_id,credit_card,risk_score.targetUser: the user to investigate.
Output
Return whether the target ring should be blocked.
Function
shouldBlockFraudRing(transactions: String[], targetUser: String) → booleanExamples
Example 1
transactions = ["Alice,D1,CC1,90","Bob,D1,CC2,0","Charlie,D2,CC2,80"]targetUser = "Alice"return = trueThe connected ring is Alice, Bob, and Charlie. Bob has score 0, so the average is (90 + 80) / 2 = 85, which is greater than 75.
Example 2
transactions = ["Alice,D1,CC1,70","Bob,D1,CC2,0","Charlie,D2,CC2,80"]targetUser = "Alice"return = falseBob still connects Alice and Charlie, but Bob is excluded from the average. (70 + 80) / 2 = 75, and the rule requires strictly greater than 75.
Constraints
- 0 <= transactions.length <= 10^5
- 0 <= risk_score <= 100
- Each user has the same risk score across all their transactions.