Problem · Array

Propagating Fraud Detector

Learn this problem
MediumAffirm logoAffirmFULLTIMEPHONE SCREEN

Problem statement

Process a batch of events in order while maintaining a set of suspicious PII entries. Each row of events contains exactly five strings in this order:

  1. the event type, either underwriting or fraud_flag;
  2. an address;
  3. a phone number;
  4. an email address;
  5. a Social Security number.

An empty string means that the corresponding PII field is absent. PII identity includes its field: two equal strings in different fields are different entries.

Apply these rules to each event:

  • For fraud_flag, add all of its non-empty PII entries to the suspicious set and append an empty string to the result.
  • For underwriting, append "1" when at least one of its non-empty PII entries is already suspicious; otherwise append "0". If the event is suspicious, add all of its non-empty PII entries to the suspicious set, allowing suspicion to propagate. A non-suspicious underwriting event does not change the set.

Return one string per input event in the same order.

Function

detectPropagatingFraud(events: String[][]) → String[]

Examples

Example 1

events = [["fraud_flag","1 Main St","111","",""],["underwriting","2 Oak St","111","b@example.com","S2"],["underwriting","3 Pine St","333","b@example.com","S3"],["underwriting","4 Elm St","444","d@example.com","S4"]]return = ["","1","1","0"]

The fraud flag seeds phone 111. The second event is suspicious through that phone and adds all of its PII, including email b@example.com. That email makes the third event suspicious. The fourth event shares nothing suspicious.

Example 2

events = [["underwriting","A","P","",""],["fraud_flag","B","Q","",""],["underwriting","A","Q","",""],["underwriting","C","P","",""]]return = ["0","","1","1"]

The first event is initially clean and does not seed suspicion. The fraud flag seeds phone Q. The third event is suspicious through Q and then propagates suspicion to address A. Its phone P also becomes suspicious, so the fourth event is flagged.

Example 3

events = [["fraud_flag","same","","",""],["underwriting","","same","",""]]return = ["","0"]

The first row marks the address value suspicious. The equal text in the second row is a phone value, so it is a different PII identity and does not match.

Constraints

  • 1 <= events.length <= 100000
  • events[i].length == 5
  • events[i][0] is either underwriting or fraud_flag.
  • Every non-empty PII value has length from 1 through 100.
  • Every event contains at least one non-empty PII field.

More Affirm problems

drafts saved locally
public String[] detectPropagatingFraud(String[][] events) {
    // Write your code here.
}
events[["fraud_flag","1 Main St","111","",""],["underwriting","2 Oak St","111","b@example.com","S2"],["underwriting","3 Pine St","333","b@example.com","S3"],["underwriting","4 Elm St","444","d@example.com","S4"]]
expected["", "1", "1", "0"]
checking account