Lowest accuracy slice

Write codeMedium16 minGoogle and Anthropic style

Your task

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".

Examples

weakest_slice(groups: list[str], y_true: list[int], y_pred: list[int]) -> str
Example 1
Inputweakest_slice(["us", "us", "eu", "eu"], [1, 0, 1, 0], [1, 0, 0, 0])
Output"eu"