Solution (source code)

= Solution

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 $i$, `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 \b[$O(n)$ time and $O(1)$ auxiliary space]. Empty input yields length zero because no nonempty increasing segment exists.