Skip to content
echogeco
AI in the operation · Scoring and measurement

Pick the score threshold

Write the function that sets a lead-score threshold from call capacity and a call's break-even, never splitting a tie, and read what a second rep buys.

codemediumExercise · 3 min · 51 of 60
On this page

Last month the threshold was typed in by hand and sent 500 leads to a team that can call 300. The function below makes the cut the same way every month.

The situation

Sales receives 5,000 leads a month, of which 4% convert, and can make 300 calls. The lead score is calibrated in whole percent: leads scored 21 converted about 21% of the time last quarter. This month's scores are 100 leads at 34, 200 at 21, 200 at 12, 500 at 8, 500 at 4, 1,000 at 2, 2,000 at 1 and 500 at 0.

A call costs $25, 20 minutes of a rep at $75 an hour, and a converted lead is worth $800 of expected margin, so a call pays when score × $800 ≥ 100 × $25, a score of at least 3.125. The CRM routes with one rule, "score ≥ t", so it cannot call some leads at a score and skip others at the same score. Last month someone set t = 10, sending 500 leads to 300 calls, and reps chose among them by instinct.

The question

Write the function, then use it to say where t goes for 300 calls and what a second rep's extra 300 calls would buy.

def solve(scores, capacity, value, cost):
    """Pick the lead-score threshold for next month's call list.

    scores:   one calibrated score per lead, an integer percent.
    capacity: calls the team can make this month.
    value:    dollars of expected margin from one converted lead.
    cost:     loaded dollars of one call.
    Returns (threshold, calls): call every lead with score >= threshold.
    A lead is worth a call when score / 100 * value >= cost (break-even is called).
    Ties are never split: if calling every lead at the cut score would exceed
    capacity, the threshold stays at the score above and the spare calls are
    capacity - calls. With no lead worth a call, returns (None, 0).
    """
solve(MONTH, 300, 800, 25)              ->  (21, 300)
solve(MONTH, 400, 800, 25)              ->  (21, 300)
solve(MONTH, 600, 800, 25)              ->  (12, 500)
solve(MONTH, 5000, 800, 25)             ->  (4, 1500)
solve([30, 20, 20, 10], 2, 800, 25)     ->  (30, 1)
solve([3, 2, 1], 10, 800, 25)           ->  (None, 0)

MONTH is the 5,000 scores above. The tie rule is the deterministic part of the contract: leads that share a score are all called or none is, and unused calls are reported, never filled by arrival order or lead ID.

A strong answer · Rubric · Where answers go wrong · Solution

Write your answer first, then open