Uber-inspired model-training pipeline monitors validation loss and wants to stop once improvement has stalled for a configured patience window. You need to implement the early-stopping counter exactly so the training job stops at the intended epoch.
Scan the validation losses in order. An epoch is bad if its loss is not strictly lower than the best loss so far, and a new best resets the bad-epoch counter. Return the 0-based index of the first epoch at which the counter reaches patience, or -1 if that never happens.
Implement solve(losses,patience).
Returns. Return an int.
Example 1
Input:
solve([0.9, 0.8, 0.81, 0.82], 2)
Output:
3
Example 2
Input:
solve([0.9, 0.8, 0.7], 2)
Output:
-1
No results yet
Run your code to check it against the examples, or submit to run every test.