Problem · Graph

Risky Fraud Ring

Learn this problem
MediumStripeOA
See Stripe hiring insights

Problem 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) → boolean

Complete shouldBlockFraudRing.

  • String transactions[n]: transaction rows formatted user_id,device_id,credit_card,risk_score
  • String 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 = true

The 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 = false

Bob 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

drafts saved locally
public boolean shouldBlockFraudRing(String[] transactions, String targetUser) {
  // write your code here
}
transactions["Alice,D1,CC1,90","Bob,D1,CC2,0","Charlie,D2,CC2,80"]
targetUser"Alice"
expectedtrue
checking account