Most frequent confusion pair

Write codeMedium14 minMeta style

Your task

The moderation team wants to know the model's single worst confusion: which (true category, predicted category) mistake happens most often. Given equal-length string lists y_true and y_pred, consider only the positions where the two differ. Count the occurrences of each ordered (true, predicted) pair and return the count of the most frequent pair. If the model made no mistakes (or the lists are empty), return 0. Example: y_true = ["spam", "ok", "spam", "toxic", "spam"], y_pred = ["ok", "ok", "ok", "spam", "ok"] returns 3 (the pair spam predicted as ok).

Examples

top_confusion(y_true: list[str], y_pred: list[str]) -> int
Example 1
Inputtop_confusion(["spam", "ok", "spam", "toxic", "spam"], ["ok", "ok", "ok", "spam", "ok"])
Output3