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 [19, 10, 4, 7, 13, 22, 6, 16, 8]?

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

Correct answer: D. 6

For each i combine inc[i] (LIS ending at i) and dec[i] (LDS starting at i): max(inc[i] + dec[i] − 1) = 6, e.g. 4, 7, 13, 22, 16, 8. Adding the separate LIS and LDS (4 + 4 = 8) ignores the shared peak, 9 is the whole array, and 3 is the longest decreasing contiguous run.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic