Code Room
CodingEasycod-g1345
Subject Ml metricsLevel Entry–Mid~10 minCommon in ML systems interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.