Code Room
CodingMediumcod-g1058
Subject Ml metricsLevel Mid–Senior~20 minCommon in ML systems interviewsIndustries Software development

Question

You are evaluating a binary classifier. Given two equal-length lists, y_true (the ground-truth labels, each 0 or 1) and y_pred (the predicted labels, each 0 or 1), compute precision, recall, and F1 score for the positive class (label 1). Precision = TP / (TP + FP), recall = TP / (TP + FN), and F1 = 2*P*R / (P+R). If any denominator is zero, treat that metric as 0.0. Return the three values as a list [precision, recall, f1], each rounded to 4 decimal places. Lists are non-empty and have length up to 10^5.

Implement
prf1(y_true: list[int], y_pred: list[int]) → list[float]
Examples
in[[1,0,1,1,0],[1,0,0,1,1]]out[0.6667,0.6667,0.6667]
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.