All problems
MediumMetricsv2026-06-27

Metrics ยท Medium

AUC

Measure pairwise ordering quality across positive and negative examples.

Task

Implement auc(labels: list[int], scores: list[float]) -> float. Compare every positive example with every negative example and return the probability that a randomly chosen positive receives a higher score.

Requirements

  • Count a positive-negative score tie as 0.5.
  • Return 0.0 when the input has no positive examples or no negative examples.
  • Do not assume scores are probabilities or already sorted.
  • Inputs have equal length and labels are binary.

Example

labels = [0, 1, 0, 1]
scores = [0.1, 0.9, 0.2, 0.8]

auc(labels, scores)
# 1.0
solution.pySign in to save
Public tests run locally in your browser.
Run your code to see public test results.