KatInterview

Sales Volume Needed to Hold Margin After a Menu Expansion

Math & Bit ManipulationAuto-graded · 17 test cases
EasyAuto-gradedMath & Bit Manipulationmathalgebrabreak-even

Last updated

Derive a closed-form sales volume that keeps profit margin unchanged after adding a second product with extra fixed costs, and reject unreachable targets.

A food company sold a single item last year and earned a profit margin (profit divided by revenue) of prior_margin. This year it adds a second item, and you must find how many units it needs to sell in total to end up with exactly the same margin.

All money amounts are in millions of dollars, and unit counts are in millions of units.

Product data (unchanged from last year)

ItemSelling priceVariable cost per unit
Classic$4$1
Plant-based$4$2

Units sold are split Plant-based : Classic = 2 : 3 (so 40% plant-based and 60% classic).

Fixed costs this year

  • Fixed costs that already existed: base_fixed_costs_m per year.
  • New staff training: $60 million per year.
  • New supplier contract: $2.25 million per month, which is paid for all 12 months.

Let N be the total units sold this year (in millions), following the mix above. Profit is revenue minus variable costs minus all fixed costs (existing plus new). Find the N for which

profit / revenue == prior_margin.

Function behavior

  • Return N as a float, in millions of units.
  • If no positive volume can reach the target margin (the target margin is at least the blended contribution margin of the mix), raise a ValueError.

Constraints

  • 0 <= prior_margin < 1
  • 0 <= base_fixed_costs_m <= 10^6
  • Prices, costs, mix and new fixed costs are exactly as given above.
  • Return a float. Results are compared numerically, so do not round.

Examples

Example 1

Input: volume_for_same_margin(0.25, 100)

Output: 116.875

Example 2

Input: volume_for_same_margin(0.2, 50)

Output: 76.11111111111111

Example 3

Input: volume_for_same_margin(0.3, 0)

Output: 62.14285714285714

Hints

Hint 1

Blend the two items using the 2:3 mix to get an average variable cost per unit, then the average contribution per unit (price minus that cost).

Hint 2

Write profit = contribution * N - total_fixed and revenue = 4 * N, then set profit / revenue equal to prior_margin and solve the linear equation for N.

Hint 3

Total fixed costs = base + 60 + 12 * 2.25. If the coefficient of N after rearranging is zero or negative, the margin target cannot be reached, so raise ValueError.