All problems
Early Stopping Patience
Problem
Determine the epoch where early stopping triggers. Track the best (lowest) validation loss seen; count consecutive epochs without a strict improvement and return the first index where that count reaches patience.
Return -1 if the run never triggers or the input is empty.
Hint
Reset the patience counter whenever a new best loss appears.
Test cases
case 1
in: [[1,0.9,0.85,0.87,0.88,0.89],2]
expected: 4
case 2
in: [[1,0.9,0.8],3]
expected: -1
case 3
in: [[1,1,1],1]
expected: 1
case 4
in: [[],2]
expected: -1
Starter codePython
def early_stopping_epoch(val_losses, patience):
# Your code here
pass4 test cases · run your code against them in the editor