GATE Computer ScienceHardGATE CS (PYQ pattern)

The length of the longest bitonic subsequence (strictly increasing and then strictly decreasing; either part may be empty-length-1) of [4, 9, 2, 10, 5, 8, 12, 3, 6, 11, 1, 7] is:

  1. A. 5
  2. B. 6
  3. C. 7
  4. D. 8

Correct answer: B. 6

Compute LIS ending at i (I[i]) and LDS starting at i (D[i]); the maximum of I[i] + D[i] − 1 is 6, for instance 4, 9, 10, 12, 11, 7 or 4, 5, 8, 12, 11, 7. The plain LIS (length 5) is not the answer, because adding a descending tail helps.

More Algorithms questions

Exams that ask this topic