Code RoomSample ratio mismatch detection
MediumPrep Room Coding #552

Sample ratio mismatch detection

CodingAlgorithms & data structuresEntry–Mid~15 min

Before reading any experiment result, a healthy A/B pipeline checks for sample-ratio mismatch: did each variant actually receive its intended share of traffic? Given counts (observed visitors per variant), expected_pct (intended percentage per variant, same length), and an integer tolerance tol_pct, let total be the sum of counts. Variant i is flagged when |100 * counts[i] - expected_pct[i] * total| > tol_pct * total, using exact integer arithmetic. Return the flagged indices in increasing order. If total is 0, return an empty list. Example: counts = [560, 440], expected_pct = [50, 50], tol_pct = 2 returns [0, 1].

Implement
srm_flags(counts: list[int], expected_pct: list[int], tol_pct: int) → list[int]
Examples
in[[560,440],[50,50],2]out[0,1]
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 15 min
InputExpectedGot
[[560,440],[50,50],2][0,1]not run yetsample