Code Room
CodingEasycod-g1335
Subject Ml metricsLevel Entry–Mid~10 minCommon in ML systems · Algorithms & data structures interviewsIndustries Software development

Question

Your team ships a spam filter and the eval dashboard needs the four confusion-matrix cells. Given two equal-length lists of binary labels, y_true and y_pred (1 = spam, 0 = not spam), return the list [tp, fp, fn, tn] where tp counts pairs with true 1 and predicted 1, fp counts true 0 predicted 1, fn counts true 1 predicted 0, and tn counts true 0 predicted 0. Example: y_true = [1, 0, 1, 1, 0], y_pred = [1, 1, 0, 1, 0] gives [2, 1, 1, 1].

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