Code Room
CodingMediumcod-g1337
Subject Ml metricsLevel Entry–Mid~14 minCommon in ML systems · Algorithms & data structures interviewsIndustries Software development

Question

A moderation model assigns each post one string category. For one target category, compute precision and recall scaled to integers. Given equal-length lists y_true and y_pred and a target category, let tp be positions where both equal target, predicted be positions where y_pred equals target, and actual be positions where y_true equals target. Return [floor(1000 * tp / predicted), floor(1000 * tp / actual)]. If predicted is 0 use -1 for the first value; if actual is 0 use -1 for the second. Example: y_true = ["toxic", "ok", "toxic", "spam"], y_pred = ["toxic", "toxic", "ok", "spam"], target "toxic" gives [500, 500].

Implement
class_prec_recall(y_true: list[str], y_pred: list[str], target: str) → list[int]
Examples
in[["toxic","ok","toxic","spam"],["toxic","toxic","ok","spam"],"toxic"]out[500,500]
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.