Code RoomVariant winner with guardrail
MediumPrep Room Coding #556

Variant winner with guardrail

CodingAlgorithms & data structuresEntry–Mid~16 min

A growth experiment ships only if the variant wins the primary metric without wrecking a guardrail. Each arm is given as [conversions, visitors, unsubscribes] with visitors >= 1. Declare the variant the winner (return 1) exactly when both hold, using integer arithmetic only: (1) its conversion rate is strictly higher: variant_conv * control_visitors > control_conv * variant_visitors; and (2) its unsubscribe rate does not exceed control's by more than margin_bps basis points: 10000 * (variant_unsub * control_visitors - control_unsub * variant_visitors) <= margin_bps * control_visitors * variant_visitors. Otherwise return 0. Example: control = [50, 1000, 10], variant = [70, 1000, 12], margin_bps = 30 returns 1.

Implement
declare_winner(control: list[int], variant: list[int], margin_bps: int) → int
Examples
in[[50,1000,10],[70,1000,12],30]out1
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 16 min
InputExpectedGot
[[50,1000,10],[70,1000,12],30]1not run yetsample