Pick the lowest safe threshold for duplicate suggestions

Agent buildEasy10 min

Your task

Your bug tracker is full of duplicates. An agent suggests duplicates for a person to merge, and a wrong merge buries a real bug, so you set the agent's confidence threshold from labeled history.

Write choose_suggest_threshold(scores, is_duplicate, min_precision_pct): the calculation that picks the threshold.

  • scores (list of int): the agent's confidence for each past pair of bugs, from 0 to 100.
  • is_duplicate (list of bool): whether that pair really was a duplicate.
  • min_precision_pct (int): the lowest acceptable precision, in percent. Precision is the share of suggestions that are real duplicates.
  • Return the threshold.

Rules:

  1. Index i in each list is one pair. Stop at the end of the shorter list.
  2. At a threshold t, the agent suggests every pair with a score of at least t.
  3. Return the smallest whole number t from 0 to 100 that passes. A threshold passes when the agent suggests at least one pair and correct * 100 >= min_precision_pct * suggested. Here suggested is how many pairs it suggests, and correct is how many of those are real duplicates.
  4. If no such t exists: return 101, meaning never suggest.

Examples

choose_suggest_threshold(scores: list[int], is_duplicate: list[bool], min_precision_pct: int) -> int
Example 1
Inputchoose_suggest_threshold([90, 80, 95, 60, 99], [True, False, True, False, True], 95)
Output81
Example 2
Inputchoose_suggest_threshold([90, 80, 95, 60, 99], [True, False, True, False, True], 60)
Output0
Example 3
Inputchoose_suggest_threshold([70, 40, 55], [False, False, False], 50)
Output101