Code Room
CodingMediumcod-g985
Subject Ml metricsLevel Mid–Senior~22 minCommon in ML systems interviewsIndustries Software development, Technology

Question

Given equal-length lists of predicted and true binary labels (0 or 1), compute accuracy, precision, and recall for the positive class (1), returned as a list [accuracy, precision, recall]. Accuracy = correct / total. Precision = TP / (TP + FP); if there are no predicted positives, precision is 0.0. Recall = TP / (TP + FN); if there are no actual positives, recall is 0.0. Inputs are non-empty. Round each metric to 4 decimal places.

Implement
classification_metrics(preds: list[int], labels: list[int]) → list[float]
Examples
in[[1,0,1,0],[1,0,0,0]]out[0.75,0.5,1]
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.