I'm trying to figure out a programming problem that has mathematical foundations.
The problem says:
For an array $$a = a_1, a_2, ..., a_n$$ of values, the smooth factor of $$a$$ is the length of a longest subarray $$a_p, ..., a_q$$ of $$ a (1 \leq p \leq q \leq n)$$ such that there is at most one $$i (p < i \leq q)$$ such that $$a_{i−1} > a_i$$where < is some fixed order on the values in $a$. The higher the smooth factor, the more effective the smooth phase is.
For example, under the natural order of integer numbers, for the array $1, 2, 3$ the smooth factor is $3$ and for the array $1, 2, 1, 2, 1, 2, 3, 1$ the smooth factor is $5$. In the first case the entire array serves as a witness and in the second case the witness is $1, 2, 1, 2, 3$.
I understand this problem is: find the largest sequence of consecutive numbers in ascending order of the set of numbers that give me.
However the example, two "$1, 2, 1, 2, 3$" escapes from this sequence.
Can they give me an idea?
Annex another set of examples:
1, 1, 1, 1, 2, 2, 3, 3 = 8
3, 4, 5, 7, 6, 8, 9, 2, 1 = 7
1, 1, 1, 1, 1, 1, 1, 1, 2 = 9
"the largest sequence of consecutive numbers in ascending order" or two such sequences concatenated with only one "decrease" between them, according to this:
"at most one" is "1 or 0". So,
1. purely non-descending sequence does
2. non-descending sequence with only 1 "break" (labeled "&" below)
E.g. 1,2 & 1,2,3 and
$1\le 1\le 1\le 1\le 2\le 2\le 3\le 3$
$3\le 4\le 5\le 7\le 6\le 8\le 9\& 2$
$1\le 1\le 1\le 1\le 1\le 1\le 1\le 1\le2$ in the cases above.