For our purposes, a trend is a contiguous subsequence of an array that falls into one of three categories:
- increasing, e.g.
- decreasing, e.g.
- stable, e.g.
[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.
Given an array of at least two integers in any reasonable format, output the trends of the array.
- You must output the smallest possible number of trends.
[[1,1], [1,2], [2,3]]is not valid output for
- 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.