Code RoomModeration threshold tuning
MediumPrep Room Coding #531

Moderation threshold tuning

CodingML systemsEntry–Mid~15 min

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).

Implement
best_threshold(scores: list[int], labels: list[int], candidates: list[int]) → int
Examples
in[[10,80,55,95,30,70],[0,1,0,1,0,1],[50,60,90]]out60
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 15 min
InputExpectedGot
[[10,80,55,95,30,70],[0,1,0,1,0,1],[50,60,90]]60not run yetsample