Churn prediction within tolerance

Write codeEasy10 min

Your task

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.

Examples

within_tolerance(y_true: list[int], y_pred: list[int], tolerance: int) -> int
Example 1
Inputwithin_tolerance([30, 60, 10], [35, 80, 10], 5)
Output2