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 [20, 21, 13, 2, 10, 11, 28, 12, 3]?

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

Correct answer: B. 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. 2, 10, 11, 28, 12, 3. 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