Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

The longest bitonic subsequence of an array is a subsequence that first strictly increases and then strictly decreases (either part may be empty). What is the length of the longest bitonic subsequence of [1, 11, 2, 10, 4, 5, 2, 1]?

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

Correct answer: D. 6

Compute inc[i] (longest increasing ending at i) and dec[i] (longest decreasing starting at i), then take the maximum of inc[i] + dec[i] − 1 over all peaks i. Simply adding the LIS and LDS lengths double-counts the peak and can use different elements.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic