2 ms·
Yeah, though at this point it would help to be a bit more explicit about what we even want. The most consistent interpretation I can come up with as follows: -
by contravariant 5y ago
Yeah, though at this point it would help to be a bit more explicit about what we even want. The most consistent interpretation I can come up with as follows:
- Partition the list into strictly monotonic runs (either increasing or decreasing)
- Reverse the decreasing runs.
But writing a version that is entirely bug free turns out to be surprisingly tricky.
You also need to be careful about how you allow runs to be split up. You can't require each run to be maximally large because then [1,2,3,4,3,2,1] must be partitioned into overlapping runs. You also can't just require the list to be partition into any set of monotonic runs, because then [[1],[2],[3],[4]] is a valid partition of [1,2,3,4]. This is especially a problem when you allow runs that aren't strictly monotonic.