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 [13, 15, 21, 26, 14, 11, 2, 23, 12]?
- A. 8
- B. 4
- C. 7
- D. 6
Correct answer: C. 7
For each i combine the longest increasing subsequence ending at i with the longest decreasing one starting at i: max(inc[i] + dec[i] − 1) = 7. Adding the overall LIS (4) and LDS (4) ignores that they must share a peak.
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
- Unit-time jobs (deadline, profit): J1 (2, 63), J2 (1, 38), J3 (2, 38), J4 (4, 52), J5 (2, 86), J6 (1, 75), J7 (1, 40). One job runs at a…
- A rooted tree has 7 nodes with 1 child, 2 nodes with 2 children, 4 nodes with 3 children, 8 nodes with 4 children, and every other node is…
- In how many ways can a convex polygon with 7 vertices be divided into triangles by non-crossing diagonals?
- Coins of denominations 1, 2, 8, 10 are available in unlimited supply. What is the minimum number of coins needed to make 16, and how many…
- Heap sort (ascending) is run on [3, 13, 29, 24, 7, 25, 19, 40]: build a max-heap bottom-up, then repeatedly swap the root with the last…
- Dijkstra's algorithm runs from A on the directed graph A→C (4), A→D (15), B→A (2), B→C (13), C→D (8), C→E (7), C→F (2), D→B (12), E→B (7)…