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]?
- A. 4
- B. 9
- C. 5
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A pair (a, b) can follow pair (c, d) in a chain when b < c. The pairs are [(5, 24), (39, 60), (15, 28), (27, 40), (50, 90), (1, 2), (3…
- What is the minimum number of elements you must DELETE from [9, 4, 7, 2, 10, 3, 8, 11, 5] (the rest keep their order) so that the…
- What is the length of the longest common subsequence of the strings "AGGTABQZ" and "GXTXAYBZQ"?
- What is the length of the longest common SUBSTRING (contiguous) of "ABABCABBAC" and "BABCBACAB"?
- What is the minimum number of single-character insertions, deletions and substitutions needed to turn "sunday" into "saturnday"?
- What is the minimum number of characters you must delete from "abcbdaxyzyx" so that the remaining string is a palindrome?