Code Room
CodingMediumcod-g1365
Subject Ab test mathLevel Entry–Mid~16 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

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.