Increasing here means nondecreasing, so equal neighbors remain in the same run. Change only the suffix-reset test:
best = 0; run = 0; bestStart = 0
for i = 0,...,n-1:
    if i == 0 or a[i] < a[i-1]: run = 1
    else: run = run+1
    if run > best:
        best = run; bestStart = i-run+1
return (bestStart,best)
After index , run is the longest nondecreasing suffix of the prefix and the recorded interval is a longest nondecreasing segment seen so far. The adjacent-comparison condition implies the all-pairs condition by transitivity. The scan uses time and auxiliary space. Empty input yields length zero because no nonempty increasing segment exists.

Articles by others on the same topic (0)

There are currently no matching articles.