For our purposes, a trend is a contiguous subsequence of an array that falls into one of three categories:
- increasing, e.g.
[1,2,3,10,239]
- decreasing, e.g.
[8,5,0,-3,-50]
- stable, e.g.
[7,7,7,7]
Note that [1,1,2,3]
is not a valid trend. It can be broken up into a stable trend [1,1]
and an increasing trend [1,2,3]
. In the event an array has more than one trend, its trends will always overlap by one number.
Task
Given an array of at least two integers in any reasonable format, output the trends of the array.
Rules
- You must output the smallest possible number of trends.
[[1,1], [1,2], [2,3]]
is not valid output for[1,1,2,3]
. - You must output trends in the order they occur in the input.
- You may output in any format you like as long as we can tell the trends apart.
- This is code-golf, so the code with the fewest bytes (in each language) wins.
- Standard loopholes are forbidden.
Test cases
Input | Output |
---|---|
|
|
Given an array of at least two integers
\$\endgroup\$