Data Structures & AlgorithmsHardProduct-company placement

What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [13, 15, 21, 26, 14, 11, 2, 23, 12]?

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

Correct answer: C. 7

For each i combine the longest increasing subsequence ending at i with the longest decreasing one starting at i: max(inc[i] + dec[i] − 1) = 7. Adding the overall LIS (4) and LDS (4) ignores that they must share a peak.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic