AlgoMaster Logo
AlgoMasterEvaluate a Canary Releaseeasy

Evaluate a Canary Release

easy

A canary release exposes a new version to a small traffic slice and compares its health with the stable version before wider rollout.

Design a CanaryReleaseEvaluator class:

  • CanaryReleaseEvaluator() creates a stateless evaluator.
  • String decide(int canaryErrors, int canaryTotal, int baselineErrors, int baselineTotal, int threshold) returns "rollback" or "promote".

threshold is an allowed difference in percentage points. Roll back only when:

Otherwise, promote. In particular, a canary whose rate is better than the baseline, equal to it, or exactly threshold points worse must be promoted.

Use integer cross-multiplication so the decision is exact:

Use wide integer arithmetic for every product. Each call is independent.

Example 1:

Input:

Output:

Explanation: The canary has a 5% error rate and the baseline has a 2% rate. The 3-point difference is greater than the 1-point threshold.

Example 2:

Input:

Output:

Explanation: The canary rate is 3% and the baseline rate is 2%. The difference equals the allowed 1 percentage point, so the release is promoted.

Constraints

  • 1 <= canaryTotal, baselineTotal <= 10^6
  • 0 <= canaryErrors <= canaryTotal
  • 0 <= baselineErrors <= baselineTotal
  • 0 <= threshold <= 100
  • threshold is measured in percentage points.
  • Use 64-bit integer arithmetic for intermediate products.
  • At most 100 calls are made to decide.
Hints

Loading...
CallReturns
new CanaryReleaseEvaluator()null
decide(5, 100, 2, 100, 1)"rollback"

The canary error rate is 5 percent and the baseline is 2 percent. Their 3-point gap exceeds the 1-point threshold.

Run checks these cases. Submit also runs a larger hidden set.