Code RoomLowest accuracy slice
MediumPrep Room Coding #537

Lowest accuracy slice

CodingML systemsEntry–Mid~16 min

A model's headline accuracy can hide a slice that is quietly failing. Each eval example has a group key (like a locale or device type). Given equal-length lists groups (strings), y_true, and y_pred (integers), compute each group's accuracy correct/total and return the name of the group with the lowest accuracy. Compare two groups' accuracies exactly using cross-multiplication: correct_1 * total_2 versus correct_2 * total_1. If several groups tie for lowest, return the alphabetically smallest name. Input is non-empty. Example: groups = ["us", "us", "eu", "eu"], y_true = [1, 0, 1, 0], y_pred = [1, 0, 0, 0] gives "eu".

Implement
weakest_slice(groups: list[str], y_true: list[int], y_pred: list[int]) → str
Examples
in[["us","us","eu","eu"],[1,0,1,0],[1,0,0,0]]out"eu"
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 16 min
InputExpectedGot
[["us","us","eu","eu"],[1,0,1,0],[1,0,0,0]]"eu"not run yetsample