Data Structures & AlgorithmsHardGATE CS

What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [12, 2, 25, 6, 15, 16, 21, 10, 3]?

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

Correct answer: B. 7

max(inc[i] + dec[i] − 1) = 7, e.g. 2, 6, 15, 16, 21, 10, 3 peaking at 21. Forgetting the −1 counts the peak twice (8), 4 is the decreasing tail from the maximum 25, and 3 is the longest decreasing contiguous run (21, 10, 3).

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic