Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
What is the length of the longest subsequence of [1, 2, 4, 5, 7, 8, 10] that is strictly increasing and in which every two consecutive chosen values differ by at least 2?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
dp[i] = 1 + max dp[j] over earlier j with a[i] − a[j] ≥ 2 (the strict increase is implied). Chaining with only a strict increase, without the gap condition, admits consecutive values such as 4 and 5.
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
- Using swaps of ADJACENT elements only, what is the minimum number of swaps needed to sort the binary array [1, 0, 1, 1, 0, 0, 1, 0] so…
- How many unordered pairs of positions in [3, 4, 7, 10, 2, 9] have an element sum that is a prime number?
- Coins of values 1, 5, 6 and 9 are available in unlimited supply. What is the minimum number of coins needed to make exactly 11?
- In how many ways can 100 paise be paid using coins of 1, 5, 10 and 25 paise, where the order of coins does not matter?
- In how many ways can 9 identical sweets be given to 4 distinct children so that every child gets at least one sweet?
- How many words of length 6 over a three-letter alphabet {x, y, z} have no two adjacent letters equal?