Code Room
CodingHardcod-g1059
Subject Ml metricsLevel Mid–Senior~30 minCommon in ML systems interviewsIndustries Software development

Question

Given y_true (binary labels 0/1) and scores (real-valued classifier scores, higher means more likely positive), compute the ROC-AUC using the trapezoidal rule over thresholds. Sort the unique candidate thresholds, and for each, classify a point as positive when score >= threshold. Build the ROC curve as (FPR, TPR) points including the endpoints (0,0) and (1,1), sort by FPR ascending (breaking ties by TPR), and integrate the area under the curve with the trapezoidal rule. Return the AUC rounded to 4 decimal places. There is at least one positive and one negative label; length up to 2000.

Implement
roc_auc(y_true: list[int], scores: list[float]) → float
Examples
in[[1,1,0,0],[0.9,0.6,0.4,0.1]]out1
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.