Code RoomLabel imbalance ratio
EasyPrep Room Coding #534

Label imbalance ratio

CodingML systemsEntry–Mid~10 min

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]) → int
Examples
in[[0,0,0,0,1]]out4
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 10 min
InputExpectedGot
[[0,0,0,0,1]]4not run yetsample