int a[]={11,9,8,2,10,7,3,4,5} max_length = 1 ; current_length = 1; first_position=0 ; last_position = 0 ; first_position_max=0; // Sweep one to find the length of the longest subsequence.
for ( i = 1 ; i < n ; i++ ) { if ( a[i] > a[i-1] ) { last_position=i-1; current_length=last_position- first_position+1; max_length = current_length > max_length ? current_length : max_length; first_position_max = current_length > max_length ? first_position : first_position_max; first_position= i; } } // Sweep two to print the longest subsequence. for ( i = first_position ; i < max_length ; i ++ ) { cout<< a[i]; } On Mon, Sep 6, 2010 at 2:01 PM, bittu <shashank7andr...@gmail.com> wrote: > u are given an array and u have to print the longest increasing > scattered subsequence...eg..{11,9,8,2,10,7,3,4,5}. > > > Solve it O(n); > > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.