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]?
- A. 8
- B. 6
- C. 9
- 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.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- 0/1 knapsack with capacity 17: items (weight, value) = (9, 21), (6, 19), (3, 9), (7, 13), (3, 27). What is the maximum total value?
- Coins of denominations 1, 6, 9, 10 are available in unlimited supply. What is the minimum number of coins needed to make 33, and how many…
- For the string BBABCBCAB, what are the lengths of the longest palindromic SUBSTRING and the longest palindromic SUBSEQUENCE?
- With 3 identical eggs and at most 5 drops, what is the largest number of floors for which you can always determine the critical floor (the…
- A complete binary tree (array form, all levels full except possibly the last, which is filled from the left) has 187 nodes. How many…
- The directed graph A→C (4), A→E (5), B→A (6), C→B (8), D→C (1), E→B (9), E→C (-6), E→D (2) has one negative edge but no negative cycle…