ROC-AUC computation

Write codeHard30 minMeta and Netflix style

Your task

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.

Examples

roc_auc(y_true: list[int], scores: list[float]) -> float
Example 1
Inputroc_auc([1, 1, 0, 0], [0.9, 0.6, 0.4, 0.1])
Output1