Risky Fraud Ring
Learn this problemProblem statement
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.
Function
shouldBlockFraudRing(transactions: String[], targetUser: String) → booleanComplete shouldBlockFraudRing.
String transactions[n]: transaction rows formatteduser_id,device_id,credit_card,risk_scoreString targetUser: the user to investigate
Returns
boolean: whether the target ring should be blocked.
Examples
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.
More Stripe problems
- Deployment Window SchedulerOA · Seen Jul 2026
- Directly Linked UsersOA · Seen Jun 2026
- Fraud Ring SizeOA · Seen Jun 2026
- Account Balance Manager Part 3 - Platform CoverageONSITE INTERVIEW · Seen Jun 2026
- BitFont Part 3 - Decode Run-Length-Encoded RowsONSITE INTERVIEW · Seen Jun 2026
- Record Linkage Part 3 - Full Connected ComponentPHONE SCREEN · Seen Jun 2026
- Shipping Cost Calculator Part 3 - Mixed Fixed/Incremental TiersONSITE INTERVIEW · Seen Jun 2026
- Transaction Fee Calculator - Per-Merchant Volume DiscountPHONE SCREEN · Seen Jun 2026