Code RoomSpam filter weighted cost
EasyPrep Room Coding #548

Spam filter weighted cost

CodingML systemsEntry–Mid~10 min

Not all spam-filter mistakes cost the same: quarantining a real customer email (false positive) triggers a support ticket, while letting spam through (false negative) merely annoys. Given equal-length binary lists y_true and y_pred (1 = spam), plus non-negative integer costs fp_cost and fn_cost, return the total cost: (number of positions with true 0, predicted 1) * fp_cost + (number of positions with true 1, predicted 0) * fn_cost. Example: y_true = [1, 0, 0, 1], y_pred = [0, 1, 0, 1], fp_cost = 1, fn_cost = 5 returns 6.

Implement
error_cost(y_true: list[int], y_pred: list[int], fp_cost: int, fn_cost: int) → int
Examples
in[[1,0,0,1],[0,1,0,1],1,5]out6
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 10 min
InputExpectedGot
[[1,0,0,1],[0,1,0,1],1,5]6not run yetsample