Compare with historical state18.06
Historical state is more than just previous: min so far, last index of x, prefix hash. You compare a[i] against that memory.
The history must be correct for indices < i (or ≤ i). Update history after the comparison if the comparison needed the old history.
Same skill, three traces. Read all three before you try it.
01span from last seen - given
a = [1, 2, 1],x = 1- walk
i=0recordi=2distance2- result
- gap
2
02beat historical min - given
a = [4, 1, 9]- walk
9-1uses min-so-far1, not previous1only by luck- result
- best gain
8
03stock idea - given
a = [4, 1, 9], buy min so far, sell today- walk
compare
a[i]-minSoFar then update min- result
- update after compare
maxGain(a).a is an array of integers.Return the max of
a[i] - min(a[0..i)). Update min after the compare.[4, 1, 9] → gain 8. [9, 1, 4] → gain 3.constraintsa has length ≥ 2. values are integers.
- 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.