FastPrepFraud Ring Size

Fraud Ring Size

Stripe logoStripe● MediumOA

Problem statement

Stripe Fraud Ring Tasks

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

  1. Task 1: Directly Linked Users
  2. Task 2: Fraud Ring Size (current)
  3. Task 3: Risky Fraud Ring

Direct links alone are insufficient for detecting sophisticated fraud rings, as bad actors may rotate devices to avoid simple detection logic. However, they often still share financial instruments.

A Fraud Ring is the full set of users connected by any chain of shared identifiers. If User A shares a device with User B, and User B shares a credit card with User C, then User A and User C are part of the same coordinated ring.

The goal is to quantify the size of the threat. Each transaction includes a user ID, a device ID, and a credit-card hash. Given a target user, calculate the total number of unique users within that user's extended Fraud Ring.

Input

  • transactions: a list of strings, where each string is formatted as user_id,device_id,credit_card.
  • targetUser: the user ID to investigate.

Note: A single user may appear multiple times in the transaction log with different identifiers. For example, if Alice uses Device A and Device B, she links those two devices together. Anyone on Device A is therefore connected to anyone on Device B through Alice.

Output

Return the number of unique users in the Fraud Ring containing targetUser, including targetUser.

Function

getFraudRingSize(transactions: String[], targetUser: String) → int

Examples

Example 1

transactions = ["Alice,D1,CC1","Bob,D1,CC2","Charlie,D2,CC2","David,D3,CC3","Eve,D3,CC4"]targetUser = "Alice"return = 3

Alice used Device D1. Bob also used Device D1, linking Alice and Bob.

Bob used Credit Card CC2. Charlie also used Credit Card CC2, linking Bob and Charlie.

David is on Device D3 and Card CC3, sharing no overlap with the Alice—Bob—Charlie cluster. Eve is on Device D3, linking Eve to David, but they remain disjoint from Alice.

The extended ring containing Alice consists of {Alice, Bob, Charlie}, resulting in a size of 3.

Example 2

transactions = ["A,D1,C1","B,D2,C2","C,D3,C3"]targetUser = "A"return = 1

No other user shares an identifier with A, so its Fraud Ring contains only A.

Constraints

  • 1 <= transactions.length <= 10^5.
  • Every transaction contains exactly three non-empty, comma-free fields: user_id, device_id, and credit_card.
  • targetUser appears in at least one transaction.
  • A user may appear in multiple transactions, and every occurrence represents the same user.

More Stripe problems

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