KatInterview

Calculate Product Mix Profitability Metrics

Math & Bit ManipulationAuto-graded · 16 test cases

Last updated

Computes baseline and mix-shifted unit profit averages, per-unit margin delta, and overall impact on profit given total volume.

Consider two operating scenarios for selling burgers:

  • Scenario A: Only Regular burgers are sold.
  • Scenario B: Both Regular and Vegan burgers are sold, with a sales ratio of Vegan to Regular equal to $2:3$, and total unit sales remaining unchanged.

The pricing and unit cost structure for each burger type is as follows:

  • Regular: Price = $4, Unit Cost = $1.
  • Vegan: Price = $4, Unit Cost = $2.

Given total_burgers, representing the total number of units sold, compute the following metrics in order:

  1. Average profit per burger in Scenario A.
  2. Average profit per burger in Scenario B.
  3. Difference in average profit per burger between Scenario B and Scenario A ($\text{Scenario B} - \text{Scenario A}$).
  4. Total profit change across all total_burgers units ($\text{Difference} \times \text{total_burgers}$).

Return these four results as a list of floating-point numbers: [avg_a, avg_b, diff, total_change].

Constraints

  • $1 \le \text{total_burgers} \le 10^9$

Examples

Example 1

Input: compare_average_profit(1000000)

Output: [3, 2.6, -0.3999999999999999, -399999.9999999999]

Hints

Hint 1

Determine the unit margin for each burger variant by subtracting unit cost from price.

Hint 2

Convert the Vegan:Regular ratio of 2:3 into unit proportions (Vegan = 2/5, Regular = 3/5).

Hint 3

Multiply the unit profit difference by total_burgers to get total profit impact.