Keep best-so-far18.04
Best-so-far is a running champion: max, min, best window, best pair. Update when the current candidate beats it.
Initialize from the first legal candidate, not from 0 unless 0 is a legal score. Record the index/bounds when you update.
Same skill, three traces. Read all three before you try it.
01max - given
a = [4, 1, 9, 1]- walk
best
4, stays, becomes9, stays- result
9at index2
02best sum window of 2 - given
a = [4, 1, 9, 1]- walk
4+1=51+9=10best9+1=10tie keep first- result
- window
[1, 2]sum10
03init trap - given
a = [-3, -1, 2], max starting at0- walk
0is not in the array- result
- wrong; init
a[0]
bestSoFar(a).a is an array of integers.Track the max value and the best length-
2 sum. Initialize from real candidates, not from 0.On
[-3, -1, 2], max is 2. On [4, 1, 9, 1], max is 9 at index 2 and best length-2 sum is 10 at [1, 2].constraintsa is a non-empty integer array.
- Best Time to Buy and Sell Stock0/3 skills ready · arrays · easyopen
- Best Time to Buy and Sell Stock0/3 skills ready · arrays · easyopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.