F1 score model comparison
Two spam-filter candidates were scored on the same eval set. Each model is summarized as [tp, fp, fn]. Its F1 score is 2*tp / (2*tp + fp + fn); if 2*tp + fp + fn is 0, treat that model's F1 as 0. Return 0 if model_a has the strictly higher F1, 1 if model_b does, and -1 on an exact tie. Compare the two fractions exactly with integer cross-multiplication — do not use floating point. Example: model_a = [8, 2, 2] (F1 = 16/20) beats model_b = [9, 4, 1] (F1 = 18/23), so return 0.
Implement
better_f1(model_a: list[int], model_b: list[int]) → intExamples
in
[[8,2,2],[9,4,1]]out0What 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 15 min
solution.py
InputExpectedGot
[[8,2,2],[9,4,1]]0not run yetsample