KatInterview

Calculate QR Campaign Funnel Metrics

Math & Bit ManipulationAuto-graded · 21 test cases
EasyAuto-gradedMath & Bit Manipulationmathfunnel-analysisconversions

Last updated

Tests understanding of multi-stage conversion funnels by computing metrics at each step given input rates.

You are analyzing a marketing campaign that displays a QR code during a televised event. Your task is to calculate key funnel metrics at each stage of user engagement.

Given the total number of viewers and rates for each conversion step, compute the number of people at each stage:

  1. Device-equipped viewers: viewers who own a smartphone
  2. Attentive viewers: device-equipped viewers who are actually watching the screen during the ad
  3. Scans: attentive viewers who scan the QR code
  4. Uses: scanners who complete the desired action (e.g., sign up, redeem offer)

Write a function that takes five parameters:

  • total_viewers (int): the total audience size
  • device_rate (float): the fraction of viewers who own a smartphone (0.0 to 1.0)
  • attention_rate (float): the fraction of device owners who are watching during the ad (0.0 to 1.0)
  • scan_rate (float): the fraction of attentive device owners who scan the code (0.0 to 1.0)
  • conversion_rate (float): the fraction of scanners who complete the final action (0.0 to 1.0)

Return a dictionary with four keys:

  • "device_viewers": number after applying device_rate
  • "attentive_viewers": number after applying attention_rate to device_viewers
  • "scans": number after applying scan_rate to attentive_viewers
  • "uses": number after applying conversion_rate to scans

All output values should be floats representing the computed counts at each stage.

Constraints

  • 1 ≤ total_viewers ≤ 10^9
  • 0.0 ≤ device_rate ≤ 1.0
  • 0.0 ≤ attention_rate ≤ 1.0
  • 0.0 ≤ scan_rate ≤ 1.0
  • 0.0 ≤ conversion_rate ≤ 1.0
  • Each rate represents a valid probability
  • Output values should preserve floating-point precision (no rounding required)

Examples

Example 1

Input: calculate_qr_funnel(100000000, 0.85, 0.2, 0.15, 0.1)

Output: {'device_viewers': 85000000, 'attentive_viewers': 17000000, 'scans': 2550000, 'uses': 255000}

Example 2

Input: calculate_qr_funnel(50000000, 0.9, 0.3, 0.25, 0.08)

Output: {'device_viewers': 45000000, 'attentive_viewers': 13500000, 'scans': 3375000, 'uses': 270000}

Example 3

Input: calculate_qr_funnel(120000000, 0.75, 0.1, 0.05, 0.2)

Output: {'device_viewers': 90000000, 'attentive_viewers': 9000000, 'scans': 450000, 'uses': 90000}

Hints

Hint 1

Each stage applies its rate to the output of the previous stage, forming a sequential funnel

Hint 2

The calculation flows: total → device owners → attentive → scans → uses

Hint 3

Multiply the cumulative audience by each rate in sequence; track all four intermediate results