FastPrepPrecision of Stacked PII Detector Flags

Precision of Stacked PII Detector Flags

Mercor logoMercor● EasyFULLTIMEPHONE SCREEN

Problem statement

A pipeline anonymizes customer data by replacing real names with fake ones. First, a PII detector reads a document token by token and flags every token that looks like personal information (PII).

A document has piiTokens real PII tokens and otherTokens tokens that are not PII. Every detector has these properties:

  • It flags every real PII token.
  • It flags each non-PII token with probability falseFlagPercent / 100.

The pipeline runs detectors equally good detectors and replaces a token only when all of them flag it. The detectors make their mistakes independently.

Pick a token uniformly at random from the document. Given that every detector flagged it, what is the probability that it is real PII? Return the exact answer as a reduced fraction string "numerator/denominator" with no spaces. Write a probability of 1 as "1/1".

The reported question used 100 PII tokens, 100000 other tokens, and a 1% false-flag rate, first with one detector and then with two.

Function

flaggedPiiProbability(piiTokens: int, otherTokens: int, falseFlagPercent: int, detectors: int) → String

Examples

Example 1

piiTokens = 100otherTokens = 100000falseFlagPercent = 1detectors = 1return = "1/11"

The detector flags all 100 PII tokens. Each of the 100000 other tokens is flagged with probability 1/100, which adds 1000 expected false flags.

So the probability is 100 / (100 + 1000) = 1/11, about 9%.

Example 2

piiTokens = 100otherTokens = 100000falseFlagPercent = 1detectors = 2return = "10/11"

Both detectors still flag all 100 PII tokens. A non-PII token is flagged by both with probability (1/100)^2 = 1/10000, so there are 10 expected false flags.

The probability is 100 / (100 + 10) = 10/11.

Example 3

piiTokens = 3otherTokens = 7falseFlagPercent = 50detectors = 2return = "12/19"

A non-PII token is flagged by both detectors with probability (1/2)^2 = 1/4, so the expected false flags are 7/4.

The probability is 3 / (3 + 7/4) = 12/19.

Constraints

  • 1 <= piiTokens <= 10^6
  • 0 <= otherTokens <= 10^6
  • 0 <= falseFlagPercent <= 100
  • 1 <= detectors <= 3

More Mercor problems

See Mercor hiring insights
Saved
public String flaggedPiiProbability(int piiTokens, int otherTokens, int falseFlagPercent, int detectors) {
    // Write your code here.
}
piiTokens100
otherTokens100000
falseFlagPercent1
detectors1
expected"1/11"
Checking account…