FastPrepDirectly Linked Users

Directly Linked Users

Stripe logoStripe● EasyOA

Problem statement

Stripe Fraud Ring Tasks

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

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

Financial crimes are rarely committed in isolation. Bad actors may spread activity across multiple user accounts, but shared identifiers can reveal connections.

Each transaction log entry is formatted as user_id,device_id. Two different users are directly linked if they use the same device. A single user may appear multiple times with different devices.

Given the log and a target user, return all users directly linked to the target user. The target user should not appear in the output. Return the user IDs in lexicographic order.

Input

  • transactions: transaction rows formatted as user_id,device_id.
  • targetUser: the user to investigate.

Output

Return the directly linked user IDs in lexicographic order, excluding targetUser.

Function

findDirectlyLinkedUsers(transactions: String[], targetUser: String) → String[]

Examples

Example 1

transactions = ["Alice,D1","Bob,D1","Charlie,D2","David,D3","Eve,D1"]targetUser = "Alice"return = ["Bob","Eve"]

Alice used D1. Bob and Eve also used D1.

Example 2

transactions = ["Alice,D1","Alice,D2","Bob,D2","Cara,D3"]targetUser = "Alice"return = ["Bob"]

Alice is associated with D1 and D2, and Bob shares D2.

Constraints

  • 0 <= transactions.length <= 10^5
  • User IDs and device IDs contain no commas.

More Stripe problems

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