Break-Even Volume and Unit-Economics Sensitivity

Medium · Analytics & Experimentation · Data Scientist · Technical Screen

Problem Statement

Model the single-period unit economics of a dining business and quantify how changes in fixed overhead, per-guest variable cost, and per-guest revenue affect profitability and required customer volume.

In a single operating period (such as one month): - fixed_cost (>= 0) is paid once regardless of guest volume (lease, salaried staff, insurance). - Each guest generates price in average revenue and incurs variable_cost in direct per-guest expenses (ingredients, packaging, payment fees). - customers (>= 0) is the number of guests served during the period.

Implement four pure-Python functions matching the signatures in starter.py:

  1. profit(customers, fixed_cost, price, variable_cost) -> float: Return net period profit: total guest revenue minus fixed and variable costs.
  2. customers_needed(target_profit, fixed_cost, price, variable_cost) -> Optional[int]: Return the smallest non-negative integer guest count (>= 0) whose period profit is at least target_profit. Return None whenever no non-negative guest count can reach target_profit (for example, when unit contribution price - variable_cost <= 0 and 0 guests earns less than target_profit). Handle standard IEEE-754 decimal rounding noise cleanly so exact decimal ratios do not over-round to the next integer.
  3. break_even_customers(fixed_cost, price, variable_cost) -> Optional[int]: Return the smallest non-negative integer guest count achieving period profit >= 0.0, or None if breaking even is impossible.
  4. what_if(customers, fixed_cost, price, variable_cost, fixed_cost_drop=0.0, variable_cost_drop=0.0, price_drop=0.0) -> Dict[str, Optional[float]]: Subtract fixed_cost_drop from fixed_cost, variable_cost_drop from variable_cost, and price_drop from price, then evaluate the updated business at the same baseline customers count and return a dictionary with four keys:
    • "profit": updated period profit at customers
    • "profit_change": updated profit minus baseline profit
    • "break_even": updated break_even_customers(...) (int or None)
    • "customers_to_keep_profit": smallest non-negative integer guest count needed under the updated economics to earn at least the baseline profit (int or None)

Examples

Example 1

  • Input: customers = 4000, fixed_cost = 24000.0, price = 22.0, variable_cost = 14.0
  • Output:
    • break_even_customers(24000.0, 22.0, 14.0) -> 3000
    • profit(4000, 24000.0, 22.0, 14.0) -> 8000.0
  • Explanation: Each guest contributes 22.0 - 14.0 = $8.00 toward overhead. Covering $24,000 in fixed overhead takes 24000 / 8 = 3,000 guests, and the remaining 1,000 guests generate 1000 * $8.00 = $8,000.0 in monthly profit.

Example 2

  • Input: Baseline (customers=4000, fixed_cost=24000.0, price=22.0, variable_cost=14.0):
    • Case A (fixed overhead cut): what_if(4000, 24000.0, 22.0, 14.0, fixed_cost_drop=3200.0)
    • Case B (per-guest cost cut): what_if(4000, 24000.0, 22.0, 14.0, variable_cost_drop=1.0)
  • Output:
    • Case A: {"profit": 11200.0, "profit_change": 3200.0, "break_even": 2600, "customers_to_keep_profit": 3600}
    • Case B: {"profit": 12000.0, "profit_change": 4000.0, "break_even": 2667, "customers_to_keep_profit": 3556}
  • Explanation: Trimming $3,200 from fixed overhead adds a flat +$3,200 at any volume and lowers break-even to 20800 / 8 = 2,600. Trimming $1.00 per guest raises unit margin to $9.00, adding +$4,000 across 4,000 guests; break-even is ceil(24000 / 9) = ceil(2666.67) = 2,667 guests, and matching the old $8,000 profit requires ceil(32000 / 9) = 3,556 guests.

Example 3

  • Input: Baseline (customers=4000, fixed_cost=24000.0, price=22.0, variable_cost=14.0) with price_drop = 3.0
  • Output: {"profit": -4000.0, "profit_change": -12000.0, "break_even": 4800, "customers_to_keep_profit": 6400}
  • Explanation: Dropping average check by $3.00 (13.6%) shrinks unit contribution from $8.00 to $5.00, swinging monthly profit by -$12,000 into a -$4,000 loss. Break-even rises to 24000 / 5 = 4,800 guests, and earning the original $8,000 profit now demands 32000 / 5 = 6,400 guests (+60% more traffic).

Constraints

  • 0.0 <= customers <= 10^9
  • 0.0 <= fixed_cost <= 10^9
  • 0.0 <= price, variable_cost <= 10^6
  • Drops in what_if may leave new_price - new_variable <= 0, in which case unreachable targets must return None.
  • Customer-count return values (customers_needed, break_even_customers, "break_even", "customers_to_keep_profit") must be whole int values (>= 0) or None.

Step-by-step walkthrough

  1. Set up the monthly operating model

    We analyze one operating period (one month) of a fast-casual bistro using concrete figures from our examples while writing general Python functions that accept any inputs:

    • Fixed overhead (F = $24,000): bills owed once per month regardless of foot traffic — lease, salaried managers, insurance, and base utilities.
    • Average check (p = $22): gross revenue brought in per guest.
    • Variable cost per guest (v = $14): expenses triggered only when an order is placed — ingredients, packaging, and card-processing fees.
    • Baseline guest volume (N = 4,000 guests): normal monthly guest traffic.
    Revenue collected per guest:   p = $22
    Direct cost per guest:        -v = -$14
                                  ---------
    Unit contribution margin:      m = $8    (first covers $24,000 overhead, then adds profit)
    

    Whenever a case prompt asks how profit responds when "costs fall", clarify right away whether fixed overhead falls (say lease drops by $3,200) or per-guest variable cost falls (say food waste drops by $1.00 per order). Those two levers scale completely differently with guest volume, and contrasting them is a central business takeaway.

  2. Express period profit through contribution margin

    Net profit for a period equals total revenue minus fixed and variable expenses. Across N guests, revenue is N * p, and total cost is F + N * v:

    profit(N) = revenue - total_cost
              = (N * p) - (F + N * v)
              = N * (p - v) - F
    

    The term m = p - v is the contribution margin: the dollars retained from one guest after covering their variable cost, which first pay down F and then accumulate as profit.

    In Example 1: - m = 22 - 14 = $8 per guest. - profit(4000) = 4000 * 8 - 24000 = 32000 - 24000 = $8,000 per month.

    def profit(customers: float, fixed_cost: float, price: float, variable_cost: float) -> float:
        """Profit for one period: revenue minus fixed and variable costs."""
        # Total money brought in across all customers in the period.
        revenue = customers * price
        # Fixed costs are paid once per period; variable costs scale with customer count.
        total_cost = fixed_cost + customers * variable_cost
        return revenue - total_cost
    
  3. Solve for break-even and target-profit guest volume

    The break-even point is the smallest whole number of guests with profit >= 0. Because what_if also computes the guest count needed to preserve the baseline $8,000 profit after a cost or price shift, solve the general inequality profit(N) >= T for any target T (break-even is T = 0):

    N * (p - v) - F >= T
    N * m           >= T + F          (add F to both sides)
    N               >= (T + F) / m    (divide by m when m > 0)
    

    At T = 0 in Example 1, N >= (0 + 24000) / 8 = 3,000 guests. Whenever (T + F) / m is fractional — such as 24000 / 9 = 2666.67 in Example 2 Case B — you cannot serve two-thirds of a guest: - At 2,666 guests, profit is 2666 * 9 - 24000 = -$6 (still below $0). - At 2,667 guests, profit is 2667 * 9 - 24000 = +$3 (at or above $0).

    So we always round up using math.ceil, never round.

  4. Guard non-positive margins and IEEE-754 rounding noise

    Three edge cases matter when turning N >= (T + F) / m into reliable code:

    1. Zero or negative unit margin (m <= 0): If price drops to $13 while variable_cost is $14, every additional guest increases losses. Serving 0 guests achieves the highest possible profit (-F). If -F >= T, return 0; otherwise no guest volume can ever reach T, so return None.
    2. Target already met at zero guests (T + F <= 0): When F = $2,000 and T = -$5,000, (T + F) / m is negative, so clamp at 0 via max(0, ...).
    3. Binary floating-point dust: In base-2 floating point, 0.3 - 0.2 is 0.09999999999999998, making 1.1 / (0.3 - 0.2) evaluate to 11.000000000000004 rather than 11.0, and (0.4 - 0.1) - 0.3 evaluates to +5.55e-17 rather than 0.0. Small relative tolerances (1e-12 for zero-margin checks and 1e-10 * max(1.0, abs(exact_customers)) before math.ceil) absorb binary rounding noise without swallowing genuine one-cent shortfalls.
    from typing import Optional
    import math
    
    
    def customers_needed(target_profit: float, fixed_cost: float, price: float,
                         variable_cost: float) -> Optional[int]:
        """Smallest whole number of customers (>= 0) whose profit is at least target_profit.
    
        Returns None when no number of customers reaches the target.
        """
        # Contribution margin: dollars left from one customer after paying their variable cost.
        margin = price - variable_cost
    
        # Guard against IEEE-754 subtraction dust when price and variable_cost are equal
        # after a what-if adjustment (e.g., (0.4 - 0.1) - 0.3 = +5.55e-17 instead of 0.0).
        margin_tolerance = 1e-12 * max(abs(price), abs(variable_cost))
        if margin <= margin_tolerance:
            # When each customer adds $0 or loses money, 0 customers gives the highest profit (-fixed_cost).
            profit_at_zero = -fixed_cost
            target_tolerance = 1e-12 * max(abs(target_profit), abs(fixed_cost))
            if profit_at_zero >= target_profit - target_tolerance:
                return 0
            return None
    
        # Continuous solution to: customers * margin - fixed_cost >= target_profit.
        exact_customers = (target_profit + fixed_cost) / margin
    
        # Subtract a tiny relative tolerance before math.ceil so exact ratios with float noise
        # (like 1.1 / (0.3 - 0.2) = 11.000000000000004) do not falsely round up to the next integer.
        rounding_tolerance = 1e-10 * max(1.0, abs(exact_customers))
        whole_customers = math.ceil(exact_customers - rounding_tolerance)
    
        # Customer counts cannot be negative when target_profit + fixed_cost <= 0.
        return max(0, whole_customers)
    
    
    def break_even_customers(fixed_cost: float, price: float, variable_cost: float) -> Optional[int]:
        """Smallest whole number of customers with profit >= 0, or None if the restaurant never breaks even."""
        # Breaking even is reaching a target profit of $0.00.
        return customers_needed(0.0, fixed_cost, price, variable_cost)
    
  5. Compare per-unit sensitivity across levers

    Holding the other variables fixed in profit = N * (p - v) - F reveals how each lever scales:

    Single-unit shift            Algebraic profit delta      Effect at N = 4,000, m = $8
    --------------------------   -------------------------   ---------------------------
    Fixed cost F drops by $1     +$1                         +$1
    Variable cost v drops by $1  +N dollars                  +$4,000
    Average check p drops by $1  -N dollars                  -$4,000
    Guest count N rises by 1     +m dollars                  +$8
    

    A $1 change in p or v is amplified 4,000 times across every guest, whereas $1 saved on F occurs once. Two standard finance ratios summarize baseline risk:

    • Margin of safety: the share of current volume the bistro can lose before profit reaches $0, (4000 - 3000) / 4000 = 25.0%.
    • Operating leverage: total contribution (N * m = $32,000) divided by profit ($8,000), equal to 32000 / 8000 = 4.0. An operating leverage of 4.0 means a 10% dip in guest traffic (400 guests) cuts monthly profit by 4 * 10% = 40% (-$3,200, down to $4,800).
  6. Implement `what_if` and trace Examples 2 and 3

    what_if(...) applies the specified drops to fixed_cost, variable_cost, and price, then compares updated profit, break-even volume, and required volume to preserve baseline profit.

    from typing import Dict, Optional
    
    
    def what_if(customers: float, fixed_cost: float, price: float, variable_cost: float,
                fixed_cost_drop: float = 0.0, variable_cost_drop: float = 0.0,
                price_drop: float = 0.0) -> Dict[str, Optional[float]]:
        # Phase 1: compute the updated unit-economics inputs after applying each drop.
        new_fixed = fixed_cost - fixed_cost_drop
        new_variable = variable_cost - variable_cost_drop
        new_price = price - price_drop
    
        # Phase 2: compare new profit against baseline profit at the same customer volume.
        old_profit = profit(customers, fixed_cost, price, variable_cost)
        new_profit = profit(customers, new_fixed, new_price, new_variable)
    
        # Phase 3: return summary dict {metric_name: float_or_int_or_None} for the new scenario.
        new_break_even = break_even_customers(new_fixed, new_price, new_variable)
        keep_profit_count = customers_needed(old_profit, new_fixed, new_price, new_variable)
        return {
            "profit": new_profit,
            "profit_change": new_profit - old_profit,
            "break_even": new_break_even,
            "customers_to_keep_profit": keep_profit_count,
        }
    

    Tracing all scenarios at N = 4,000:

    Scenario                       Margin m   Break-even    Profit      Change     Guests to keep $8k
    ----------------------------   --------   ----------   --------   ----------   ------------------
    Example 1 (F=24k, p=22, v=14)    $8.00      3,000       $8,000         $0            4,000
    Example 2A (Fixed -$3,200)       $8.00      2,600      $11,200     +$3,200           3,600
    Example 2B (Variable -$1.00)     $9.00      2,667      $12,000     +$4,000           3,556
    Example 3  (Price -$3.00)        $5.00      4,800      -$4,000    -$12,000           6,400
    
  7. Explain the business implications

    • Untargeted price cuts erode profit rapidly: Reducing the average check by $3 is only a 13.6% discount (3 / 22), yet it removes 37.5% of the $8 contribution margin and swings the business from +$8,000 profit into a -$4,000 monthly loss (-$12,000 change). Merely returning to $8,000 profit requires 6,400 guests (+60% traffic), implying a price elasticity of demand (percentage volume gain divided by percentage price cut) above 60% / 13.6% = 4.4, which rarely materializes without straining seating and kitchen capacity.
    • Variable-cost savings scale with growth: Saving $1 (7.1%) per order via portion control or supplier negotiation adds +$4,000 (+50%) at 4,000 guests and +$5,000 if traffic grows to 5,000 guests, as long as meal quality and repeat visits stay intact.
    • Fixed-cost reductions cushion downturns: Negotiating $3,200 off monthly overhead adds +$3,200 at every traffic level and cuts break-even by 400 guests, protecting newer or seasonal locations when foot traffic dips.
    • Transfer to financial services: Consumer lenders such as OneMain Financial evaluate loan portfolios with the exact same structure — branch/servicing fixed overhead is paid down by per-loan contribution margin (interest income minus funding cost, origination cost, and expected credit losses).
  8. Complete solution

    from typing import Dict, Optional
    import math
    
    
    def profit(customers: float, fixed_cost: float, price: float, variable_cost: float) -> float:
        """Profit for one period: revenue minus fixed and variable costs."""
        # Total money brought in across all customers in the period.
        revenue = customers * price
        # Fixed costs are paid once per period; variable costs scale with customer count.
        total_cost = fixed_cost + customers * variable_cost
        return revenue - total_cost
    
    
    def customers_needed(target_profit: float, fixed_cost: float, price: float,
                         variable_cost: float) -> Optional[int]:
        """Smallest whole number of customers (>= 0) whose profit is at least target_profit.
    
        Returns None when no number of customers reaches the target.
        """
        # Contribution margin: dollars left from one customer after paying their variable cost.
        margin = price - variable_cost
    
        # Guard against IEEE-754 subtraction dust when price and variable_cost are equal
        # after a what-if adjustment (e.g., (0.4 - 0.1) - 0.3 = +5.55e-17 instead of 0.0).
        margin_tolerance = 1e-12 * max(abs(price), abs(variable_cost))
        if margin <= margin_tolerance:
            # When each customer adds $0 or loses money, 0 customers gives the highest profit (-fixed_cost).
            profit_at_zero = -fixed_cost
            target_tolerance = 1e-12 * max(abs(target_profit), abs(fixed_cost))
            if profit_at_zero >= target_profit - target_tolerance:
                return 0
            return None
    
        # Continuous solution to: customers * margin - fixed_cost >= target_profit.
        exact_customers = (target_profit + fixed_cost) / margin
    
        # Subtract a tiny relative tolerance before math.ceil so exact ratios with float noise
        # (like 1.1 / (0.3 - 0.2) = 11.000000000000004) do not falsely round up to the next integer.
        rounding_tolerance = 1e-10 * max(1.0, abs(exact_customers))
        whole_customers = math.ceil(exact_customers - rounding_tolerance)
    
        # Customer counts cannot be negative when target_profit + fixed_cost <= 0.
        return max(0, whole_customers)
    
    
    def break_even_customers(fixed_cost: float, price: float, variable_cost: float) -> Optional[int]:
        """Smallest whole number of customers with profit >= 0, or None if the restaurant never breaks even."""
        # Breaking even is reaching a target profit of $0.00.
        return customers_needed(0.0, fixed_cost, price, variable_cost)
    
    
    def what_if(customers: float, fixed_cost: float, price: float, variable_cost: float,
                fixed_cost_drop: float = 0.0, variable_cost_drop: float = 0.0,
                price_drop: float = 0.0) -> Dict[str, Optional[float]]:
        """Apply the drops and return a dict with:
    
        "profit"                    profit after the change, same number of customers
        "profit_change"             profit after minus profit before
        "break_even"                break-even customer count after the change (None if never)
        "customers_to_keep_profit"  customers needed after the change to earn the old profit (None if never)
        """
        # Phase 1: compute the updated unit-economics inputs after applying each drop.
        new_fixed = fixed_cost - fixed_cost_drop
        new_variable = variable_cost - variable_cost_drop
        new_price = price - price_drop
    
        # Phase 2: compare new profit against baseline profit at the same customer volume.
        old_profit = profit(customers, fixed_cost, price, variable_cost)
        new_profit = profit(customers, new_fixed, new_price, new_variable)
    
        # Phase 3: return summary dict {metric_name: float_or_int_or_None} for the new scenario.
        new_break_even = break_even_customers(new_fixed, new_price, new_variable)
        keep_profit_count = customers_needed(old_profit, new_fixed, new_price, new_variable)
        return {
            "profit": new_profit,
            "profit_change": new_profit - old_profit,
            "break_even": new_break_even,
            "customers_to_keep_profit": keep_profit_count,
        }
    

    ✅ Submit now — all tests should pass.

Intuition & how it works

Picture a neighborhood bistro starting every month at the bottom of a $24,000 trench representing its fixed cost (expenses like rent and salaried managers owed even when zero guests dine in). Each guest pays $22 at the counter, yet $14 immediately leaves through the kitchen to cover their variable cost (ingredients, takeout containers, and payment processing). Only the remaining $8 — the contribution margin, defined as revenue minus variable cost from one sale — stays behind to fill the $24,000 trench first and generate profit afterward.

Naive reasoning divides fixed overhead by the full $22 menu price (24,000 / 22 = 1,091 guests), overlooking the $14 spent preparing each meal, or treats "cost reductions" as interchangeable without noticing that $1 saved per plate multiplies across all 4,000 guests while $1 trimmed from rent happens once. Naive implementations also break when unit margin becomes zero or negative (dividing by zero or returning negative counts) or when IEEE-754 binary rounding turns an exact integer ratio like 11 into 11.000000000000004 and rounds up to 12.

Trace our baseline (fixed_cost = $24,000, price = $22, variable_cost = $14, customers = 4,000) and Example 3 ($3 price drop): 1. Unit contribution margin: $22 - $14 = $8 per guest. 2. Break-even count: $24,000 / $8 = 3,000 guests to reach $0 profit. 3. Baseline profit: 4,000 * $8 - $24,000 = $8,000 (the 1,000 guests above break-even add $8 each). 4. What-if ($3 price drop to $19): unit margin shrinks to $19 - $14 = $5, monthly profit drops to 4,000 * $5 - $24,000 = -$4,000 (-$12,000 swing), break-even climbs to $24,000 / $5 = 4,800 guests, and earning the original $8,000 profit now demands ($8,000 + $24,000) / $5 = 6,400 guests (+60% more foot traffic).

Complexity

  • Time: O(1) per call across profit, customers_needed, break_even_customers, and what_if, since each function performs a constant number of floating-point operations and one math.ceil without iterating over customers.
  • Space: O(1) auxiliary memory, allocating only scalar numbers and the four-key dictionary returned by what_if.

Edge cases

  • Non-integer guest ratios: In Example 2 Case B (variable_cost_drop = $1, margin = $9), 24000 / 9 = 2666.67. Because 2,666 guests still lose $6, math.ceil rounds up to 2,667.
  • Zero or negative unit margin (price <= variable_cost): If price_drop = $9 lowers price to $13 against $14 variable cost, every guest loses $1. With positive fixed costs the bistro never breaks even (None); if 0 guests already satisfy target_profit (such as fixed_cost = 0 and target_profit = 0), the function returns 0.
  • Target already met at zero volume: When target_profit + fixed_cost <= 0 (for example tolerating a -$5,000 loss with $2,000 fixed cost), max(0, ...) clamps the count to 0 rather than returning a negative integer.
  • Floating-point rounding dust across scales: In binary floating point, 1.1 / (0.3 - 0.2) is 11.000000000000004, 7910000 / (322.09 - 314.18) is 1000000.0000000041, and (0.4 - 0.1) - 0.3 is +5.55e-17. Relative tolerances (1e-12 on zero-margin checks and 1e-10 on exact_customers before math.ceil) prevent spurious round-ups while still rounding genuine one-cent shortfalls like 25000000.01 / 25 = 1000000.0004 up to 1,000,001.

Common mistakes

  • Dividing fixed cost by gross price rather than contribution margin: Computing 24000 / 22 = 1,091 ignores the $14 food cost per order; at 1,091 guests the bistro actually loses 1091 * 8 - 24000 = -$15,272.
  • Failing to separate fixed-cost vs. variable-cost reductions: Saving $1 per plate yields +$4,000 at 4,000 guests, whereas saving $1 on rent yields +$1. Clarifying both scenarios demonstrates strong structured thinking.
  • Using round() instead of math.ceil(): Returning 2,666 or 2666.7 guests leaves profit slightly negative.
  • Stopping at static-volume profit change on a price cut: Reporting -$12,000 alone misses the decision threshold; showing that guest traffic must jump +60% (to 6,400 guests) lets stakeholders judge immediately whether demand elasticity and seating capacity can realistically support the discount.
  • Omitting risk ratios alongside raw dollar figures: Pairing dollar changes with the margin of safety (the percentage drop in volume a business can absorb before losing money, here (4000 - 3000) / 4000 = 25%) makes downside exposure concrete.

Follow-up questions

  • At the baseline volume of 4,000 guests, how far can average revenue per guest fall before monthly profit drops below zero? Set profit = N * (m - d) - F = 0 and solve for the maximum tolerable price drop d: d = m - F / N = 8 - 24000 / 4000 = $2.00 per guest (9.1% off the $22 check). Any cut deeper than $2.00 — such as the $3.00 cut in Example 3 — pushes monthly profit into a loss unless guest count increases.
  • How would you design a real-world experiment to test whether a $3 menu discount generates enough incremental traffic to pay for itself? First calculate the break-even traffic lift needed to hold fixed-cost-adjusted profit steady: (old_margin / new_margin) - 1 = (8 / 5) - 1 = +60% (6,400 vs. 4,000 guests). Then run a matched A/B test — a controlled experiment comparing treated locations or off-peak dayparts against an unchanged control group — and roll out the discount only if incremental volume clears +60% without hitting kitchen bottlenecks or cannibalizing full-price regulars.
  • How do the equations change when fixed overhead jumps in discrete capacity steps, such as adding $5,000 of kitchen payroll above 4,200 guests? A step cost stays constant across a capacity range and jumps once volume crosses a threshold (F = $24,000 on 0..4,200 guests and F = $29,000 on 4,201+ guests). Evaluate profit piecewise on each capacity band and watch the "profit valley" right past the jump: serving 4,300 guests earns 4300 * 8 - 29000 = $5,400, which is less than $8,000 at 4,000 guests until volume reaches (8000 + 29000) / 8 = 4,625 guests.

Follow-up questions

Similar questions

More OneMain Financial interview questions

All 15 OneMain Financial questions →