Label imbalance ratio
Before trusting an accuracy number, your team checks how skewed the eval set is: a model that always answers 'not spam' looks great on a 99-to-1 dataset. Given a list of binary labels (0s and 1s), count each class and return floor(majority_count / minority_count) as an integer imbalance ratio. If the list is empty or only one class is present, return -1. Example: [0, 0, 0, 0, 1] has 4 zeros and 1 one, so return 4.
Implement
imbalance_ratio(labels: list[int]) → intExamples
in
[[0,0,0,0,1]]out4What 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
solution.py
InputExpectedGot
[[0,0,0,0,1]]4not run yetsample