Churn prediction within tolerance
A churn model predicts each customer's remaining subscription length in days, and the product team considers a prediction 'good enough' when it lands within a tolerance of the actual value. Given non-empty equal-length integer lists y_true and y_pred and a non-negative integer tolerance, return the number of positions where the absolute difference |y_true[i] - y_pred[i]| is less than or equal to tolerance. Example: y_true = [30, 60, 10], y_pred = [35, 80, 10], tolerance = 5 returns 2.
Implement
within_tolerance(y_true: list[int], y_pred: list[int], tolerance: int) → intExamples
in
[[30,60,10],[35,80,10],5]out2What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 10 min
solution.py
InputExpectedGot
[[30,60,10],[35,80,10],5]2not run yetsample