Question: Greatest increasing/decreasing subsequence

There has to be an 'easy' way to solve this problem in Maple, but right now I am drawing a blank!  Given a sequence of random (but distinct) integers in a list, find the both the longest increasing and descreasing subsequences; finding the sequence of indices into the origninal sequence is probably the "best" answer.  My T.A. generated some massively inefficient solution to this.  While trying to solve this problem myself, I managed to get very confused amongst the various choices of doing this 'better'!  And then I thought, I must be overlooking something, this really ought to be easy.  Sure, I can come up with some fancy recursive algorithms using a graph represented via tables, but that just seems too "low level".  I keep thinking that if I just apply the right function(s) from the right package(s), this is 'already done'.  Help?

Please Wait...