FastPrepRisky Fraud Ring

Risky Fraud Ring

Stripe logoStripe● MediumOA

Problem statement

Stripe Fraud Ring Tasks

This problem is Task 3 of 3 in the Stripe fraud-ring sequence.

  1. Task 1: Directly Linked Users
  2. Task 2: Fraud Ring Size
  3. 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 as user_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) → boolean

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

See Stripe hiring insights
Saved
public boolean shouldBlockFraudRing(String[] transactions, String targetUser) {
  // write your code here
}
Checking account…