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:
profit(customers, fixed_cost, price, variable_cost) -> float: Return net period profit: total guest revenue minus fixed and variable costs.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 leasttarget_profit. ReturnNonewhenever no non-negative guest count can reachtarget_profit(for example, when unit contributionprice - variable_cost <= 0and0guests earns less thantarget_profit). Handle standard IEEE-754 decimal rounding noise cleanly so exact decimal ratios do not over-round to the next integer.break_even_customers(fixed_cost, price, variable_cost) -> Optional[int]: Return the smallest non-negative integer guest count achieving period profit>= 0.0, orNoneif breaking even is impossible.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]]: Subtractfixed_cost_dropfromfixed_cost,variable_cost_dropfromvariable_cost, andprice_dropfromprice, then evaluate the updated business at the same baselinecustomerscount and return a dictionary with four keys:"profit": updated period profit atcustomers"profit_change": updated profit minus baseline profit"break_even": updatedbreak_even_customers(...)(intorNone)"customers_to_keep_profit": smallest non-negative integer guest count needed under the updated economics to earn at least the baseline profit (intorNone)
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)->3000profit(4000, 24000.0, 22.0, 14.0)->8000.0
- Explanation: Each guest contributes
22.0 - 14.0 = $8.00toward overhead. Covering$24,000in fixed overhead takes24000 / 8 = 3,000guests, and the remaining1,000guests generate1000 * $8.00 = $8,000.0in 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)
- Case A (fixed overhead cut):
- 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}
- Case A:
- Explanation: Trimming
$3,200from fixed overhead adds a flat+$3,200at any volume and lowers break-even to20800 / 8 = 2,600. Trimming$1.00per guest raises unit margin to$9.00, adding+$4,000across4,000guests; break-even isceil(24000 / 9) = ceil(2666.67) = 2,667guests, and matching the old$8,000profit requiresceil(32000 / 9) = 3,556guests.
Example 3
- Input: Baseline
(customers=4000, fixed_cost=24000.0, price=22.0, variable_cost=14.0)withprice_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.00to$5.00, swinging monthly profit by-$12,000into a-$4,000loss. Break-even rises to24000 / 5 = 4,800guests, and earning the original$8,000profit now demands32000 / 5 = 6,400guests (+60%more traffic).
Constraints
0.0 <= customers <= 10^90.0 <= fixed_cost <= 10^90.0 <= price, variable_cost <= 10^6- Drops in
what_ifmay leavenew_price - new_variable <= 0, in which case unreachable targets must returnNone. - Customer-count return values (
customers_needed,break_even_customers,"break_even","customers_to_keep_profit") must be wholeintvalues (>= 0) orNone.
Step-by-step walkthrough
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,000guests): 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.00per order). Those two levers scale completely differently with guest volume, and contrasting them is a central business takeaway.- Fixed overhead (
Express period profit through contribution margin
Net profit for a period equals total revenue minus fixed and variable expenses. Across
Nguests, revenue isN * p, and total cost isF + N * v:profit(N) = revenue - total_cost = (N * p) - (F + N * v) = N * (p - v) - FThe term
m = p - vis the contribution margin: the dollars retained from one guest after covering their variable cost, which first pay downFand then accumulate as profit.In Example 1: -
m = 22 - 14 = $8per guest. -profit(4000) = 4000 * 8 - 24000 = 32000 - 24000 = $8,000per 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_costSolve for break-even and target-profit guest volume
The break-even point is the smallest whole number of guests with
profit >= 0. Becausewhat_ifalso computes the guest count needed to preserve the baseline$8,000profit after a cost or price shift, solve the general inequalityprofit(N) >= Tfor any targetT(break-even isT = 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 = 0in Example 1,N >= (0 + 24000) / 8 = 3,000guests. Whenever(T + F) / mis fractional — such as24000 / 9 = 2666.67in Example 2 Case B — you cannot serve two-thirds of a guest: - At2,666guests, profit is2666 * 9 - 24000 = -$6(still below$0). - At2,667guests, profit is2667 * 9 - 24000 = +$3(at or above$0).So we always round up using
math.ceil, neverround.Guard non-positive margins and IEEE-754 rounding noise
Three edge cases matter when turning
N >= (T + F) / minto reliable code:- Zero or negative unit margin (
m <= 0): Ifpricedrops to$13whilevariable_costis$14, every additional guest increases losses. Serving0guests achieves the highest possible profit (-F). If-F >= T, return0; otherwise no guest volume can ever reachT, so returnNone. - Target already met at zero guests (
T + F <= 0): WhenF = $2,000andT = -$5,000,(T + F) / mis negative, so clamp at0viamax(0, ...). - Binary floating-point dust: In base-2 floating point,
0.3 - 0.2is0.09999999999999998, making1.1 / (0.3 - 0.2)evaluate to11.000000000000004rather than11.0, and(0.4 - 0.1) - 0.3evaluates to+5.55e-17rather than0.0. Small relative tolerances (1e-12for zero-margin checks and1e-10 * max(1.0, abs(exact_customers))beforemath.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)- Zero or negative unit margin (
Compare per-unit sensitivity across levers
Holding the other variables fixed in
profit = N * (p - v) - Freveals 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 +$8A
$1change inporvis amplified4,000times across every guest, whereas$1saved onFoccurs 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 to32000 / 8000 = 4.0. An operating leverage of4.0means a10%dip in guest traffic (400guests) cuts monthly profit by4 * 10% = 40%(-$3,200, down to$4,800).
- Margin of safety: the share of current volume the bistro can lose before profit reaches
Implement `what_if` and trace Examples 2 and 3
what_if(...)applies the specified drops tofixed_cost,variable_cost, andprice, 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,400Explain the business implications
- Untargeted price cuts erode profit rapidly: Reducing the average check by
$3is only a13.6%discount (3 / 22), yet it removes37.5%of the$8contribution margin and swings the business from+$8,000profit into a-$4,000monthly loss (-$12,000change). Merely returning to$8,000profit requires6,400guests (+60%traffic), implying a price elasticity of demand (percentage volume gain divided by percentage price cut) above60% / 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%) at4,000guests and+$5,000if traffic grows to5,000guests, as long as meal quality and repeat visits stay intact. - Fixed-cost reductions cushion downturns: Negotiating
$3,200off monthly overhead adds+$3,200at every traffic level and cuts break-even by400guests, 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).
- Untargeted price cuts erode profit rapidly: Reducing the average check by
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 acrossprofit,customers_needed,break_even_customers, andwhat_if, since each function performs a constant number of floating-point operations and onemath.ceilwithout iterating overcustomers. - Space:
O(1)auxiliary memory, allocating only scalar numbers and the four-key dictionary returned bywhat_if.
Edge cases
- Non-integer guest ratios: In Example 2 Case B (
variable_cost_drop = $1,margin = $9),24000 / 9 = 2666.67. Because2,666guests still lose$6,math.ceilrounds up to2,667. - Zero or negative unit margin (
price <= variable_cost): Ifprice_drop = $9lowers price to$13against$14variable cost, every guest loses$1. With positive fixed costs the bistro never breaks even (None); if0guests already satisfytarget_profit(such asfixed_cost = 0andtarget_profit = 0), the function returns0. - Target already met at zero volume: When
target_profit + fixed_cost <= 0(for example tolerating a-$5,000loss with$2,000fixed cost),max(0, ...)clamps the count to0rather than returning a negative integer. - Floating-point rounding dust across scales: In binary floating point,
1.1 / (0.3 - 0.2)is11.000000000000004,7910000 / (322.09 - 314.18)is1000000.0000000041, and(0.4 - 0.1) - 0.3is+5.55e-17. Relative tolerances (1e-12on zero-margin checks and1e-10onexact_customersbeforemath.ceil) prevent spurious round-ups while still rounding genuine one-cent shortfalls like25000000.01 / 25 = 1000000.0004up to1,000,001.
Common mistakes
- Dividing fixed cost by gross price rather than contribution margin: Computing
24000 / 22 = 1,091ignores the$14food cost per order; at1,091guests the bistro actually loses1091 * 8 - 24000 = -$15,272. - Failing to separate fixed-cost vs. variable-cost reductions: Saving
$1per plate yields+$4,000at4,000guests, whereas saving$1on rent yields+$1. Clarifying both scenarios demonstrates strong structured thinking. - Using
round()instead ofmath.ceil(): Returning2,666or2666.7guests leaves profit slightly negative. - Stopping at static-volume profit change on a price cut: Reporting
-$12,000alone misses the decision threshold; showing that guest traffic must jump+60%(to6,400guests) 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 = 0and solve for the maximum tolerable price dropd:d = m - F / N = 8 - 24000 / 4000 = $2.00per guest (9.1%off the$22check). Any cut deeper than$2.00— such as the$3.00cut 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,400vs.4,000guests). 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,000on0..4,200guests andF = $29,000on4,201+guests). Evaluate profit piecewise on each capacity band and watch the "profit valley" right past the jump: serving4,300guests earns4300 * 8 - 29000 = $5,400, which is less than$8,000at4,000guests until volume reaches(8000 + 29000) / 8 = 4,625guests.
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?
- How would you design a real-world experiment to test whether a $3 menu discount generates enough incremental traffic to pay for itself?
- 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?
Similar questions
- Credit Card Launch Break-Even Headcount
- Optimal Linear-Demand Pricing and Validation
- Evaluate Acquisition Funnel Efficiency and Revenue
- Capped Multi-Channel Marketing Budget Optimization
- Channel Mix Economics: Physical Branches vs. Digital Onboarding
- Credit Score Cutoff Optimization for Expected Profit
More OneMain Financial interview questions
- Channel Mix Economics: Physical Branches vs. Digital Onboarding Easy
- Credit Card Launch Break-Even Headcount Easy
- Optimal Linear-Demand Pricing and Validation Medium Pro
- Evaluate Acquisition Funnel Efficiency and Revenue Medium Pro
- Capped Multi-Channel Marketing Budget Optimization Medium Pro
- Balancing Type I and Type II Errors in Proportion Tests Medium Pro
- Decision Tree Mechanics and Ensemble Methods Easy Pro
- Optimal Two-Urn Allocation for Dual Red Draws Medium Pro
- Credit Score Cutoff Optimization for Expected Profit Medium Pro
- Capacity-Capped SaaS Pricing and LTV Medium Pro