-2

Does this function return a maximal length of an increasing subsequence existing in array A[]?

int maxLength(int A[], int n) { // n - size of A[]

   int subRes[n];

   subRes[0] = 1;

   for (int i = 1; i < n; i++) {

       subRes[i] = (A[i] > A[i-1] ? subRes[i-1] + 1 : 1);
   }

   int maxL = 0;
   for (int i = 0; i < n; i++) maxL = max(maxL, subRes[i]);

   return maxL;
}

1 Answers1

0

The above solution is incorrect . The above code is for longest increasing sequence and not subsequence. For longest increasing subsequence check https://www.geeksforgeeks.org/longest-increasing-subsequence-dp-3/

dassum
  • 4,727
  • 2
  • 25
  • 38