Add
bestStart = 0 initially and, whenever a strictly longer run is found, recordbest = run
bestStart = i-run+1Then is a plateau of the returned maximum length. Keeping the old answer on equal lengths selects the earliest maximum. The loop invariant from part (a) gains the assertion that the recorded interval realizes
best; time and auxiliary-space bounds are unchanged. For empty input use the empty interval at zero. Articles by others on the same topic
There are currently no matching articles.