KatInterview

Bayesian A/B Test Launch Decision with Cost Tradeoffs

Arrays & HashingAuto-graded · 23 test cases
HardAuto-gradedArrays & Hashingbayesian-inferencedecision-analysisab-testing

Last updated

Tests whether a candidate can combine Bayesian posterior updating with expected-value analysis to make a statistically grounded product launch decision.

Problem

You are analyzing the result of an A/B test to decide whether to ship a new product feature. The test gives you a p-value and a pre-specified significance level, but a raw p-value alone does not tell you the probability that the feature actually works. You need to combine the test result with your prior belief about success, then weigh the expected financial outcomes of launching versus holding back.

Inputs

You receive the following eight parameters:

  • p_value — the p-value produced by the A/B test
  • alpha — the significance threshold (e.g. 0.05)
  • prior_benefit — your prior probability that the feature genuinely improves the metric (a value in [0, 1])
  • power — the probability that the test detects a real effect when one exists (1 − β)
  • benefit_npv — net present value of the outcome if the feature truly helps (can be positive or negative)
  • failure_npv — net present value of the outcome if the feature has no real effect or harms the metric (can be positive or negative)
  • rollout_cost — the fixed cost paid whenever you launch, regardless of whether the feature works
  • rollback_cost — the additional cost incurred only when you launch a feature that turns out not to work (reverting infrastructure, user disruption, etc.)

Task

Return True if launching the feature has a non-negative expected value compared to not launching, and False otherwise.

How to compute the answer

Step 1 — Classify the test result.
The test is significant when p_value <= alpha, and non-significant otherwise.

Step 2 — Choose the likelihoods.
The likelihood of observing this outcome depends on whether the test was significant:

Effect is realNo real effect
Significant resultpoweralpha
Non-significant result1 − power1 − alpha

Step 3 — Update the prior with Bayes' rule.
Compute the posterior probability that the effect is real:

posterior = (prior_benefit × likelihood_real) /
            (prior_benefit × likelihood_real  +  (1 − prior_benefit) × likelihood_null)

If the denominator is zero, treat the posterior as 0.

Step 4 — Compute the expected value of launching.
rollout_cost is always paid when you launch. rollback_cost is only paid when you launch and the feature fails:

EV(launch) = posterior × benefit_npv
           + (1 − posterior) × failure_npv
           − rollout_cost
           − (1 − posterior) × rollback_cost

The expected value of not launching is 0.

Step 5 — Decide.
Return True when EV(launch) >= 0.

Constraints

  • 0.0 < p_value <= 1.0
  • 0.0 < alpha <= 1.0
  • 0.0 <= prior_benefit <= 1.0
  • 0.0 < power < 1.0
  • benefit_npv, failure_npv are finite floats (may be negative)
  • rollout_cost >= 0.0
  • rollback_cost >= 0.0
  • All float inputs are well-formed (no NaN, no infinity)

Examples

Example 1

Input: evaluate_feature_launch(0.01, 0.05, 0.2, 0.8, 100000, -30000, 10000, 20000)

Output: True

Example 2

Input: evaluate_feature_launch(0.01, 0.05, 0.5, 0.8, 100000, -30000, 10000, 20000)

Output: True

Example 3

Input: evaluate_feature_launch(0.2, 0.05, 0.2, 0.8, 100000, -30000, 10000, 20000)

Output: False

Hints

Hint 1

A p-value is not the probability that the null hypothesis is true — you need Bayes' rule to convert the test outcome into a posterior probability. The likelihoods differ depending on whether the result was significant or not.

Hint 2

The rollout cost is paid in every launch scenario (both when the feature works and when it doesn't), but the rollback cost only applies when you launch a feature that has no real effect. Make sure you subtract them from the right branches of the expected-value calculation.

Hint 3

Set EV(launch) = 0 and solve for the break-even posterior to build intuition: p* = (rollout_cost + rollback_cost) / (benefit_npv − failure_npv + rollback_cost). When rollback costs are large relative to the upside, you need a much higher posterior before launching.