Equal bars count a run twice
transcript
Three hourly readings. All of them equal to two. A report rates every run by its lowest reading. Add the lowest value of every run. The answer should be twelve. The code says twenty.
Three readings make six runs in all. Each run is worth two. Six times two is twelve.
Both sides stop at a strictly lower bar. Equal bars never stop each other. So each run is counted for each equal bar. The total grows to twenty.
Let the left side stop at a strictly lower bar. That is the first rule. Let the right side stop at an equal bar. Now each run has one owner.
The correct total is twelve. Each run counts once. Both strict gives twenty. Both equal gives six, because runs are skipped.
Give every run exactly one owner. Test a list of equal values first. It exposes the bug. Full breakdown in the lecture.