Moderation threshold tuning

Write codeMedium15 minMeta and OpenAI style

Your task

You are tuning the decision threshold for a content-moderation model that outputs integer scores 0-100. At threshold t, an item is predicted 1 when its score >= t, else 0. Given scores, binary labels, and a list of candidate thresholds, return the candidate that maximizes the number of correct predictions. If several candidates tie on correct count, return the smallest such threshold value. Candidates may be unsorted. If candidates is empty, return -1. Example: scores = [10, 80, 55, 95, 30, 70], labels = [0, 1, 0, 1, 0, 1], candidates = [50, 60, 90] gives 60 (all 6 correct).

Examples

best_threshold(scores: list[int], labels: list[int], candidates: list[int]) -> int
Example 1
Inputbest_threshold([10, 80, 55, 95, 30, 70], [0, 1, 0, 1, 0, 1], [50, 60, 90])
Output60