Code RoomROC-AUC computation
HardPrep Room Coding #222

ROC-AUC computation

CodingML systemsMid–Senior~30 min

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.

0:00 of about 30 min
InputExpectedGot
[[1,1,0,0],[0.9,0.6,0.4,0.1]]1not run yetsample