Code Room
CodingMediumcod-g1342
Subject Ml metricsLevel Entry–Mid~15 minCommon in ML systems interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.