Code RoomPrecision and recall scaled
MediumPrep Room Coding #525

Precision and recall scaled

CodingML systemsAlgorithms & data structuresEntry–Mid~14 min

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.

0:00 of about 14 min
InputExpectedGot
[["toxic","ok","toxic","spam"],["toxic","toxic","ok","spam"],"toxic"][500,500]not run yetsample