Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT
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, 4), (6, 9), (10, 11)]. What is the length of the longest chain you can form? You may skip pairs, and pairs need not be used in the given order.
- A. 6
- B. 2
- C. 4
- D. 7
Correct answer: A. 6
Sort the pairs by their SECOND value and greedily take each pair whose first value is larger than the last taken second value. Sorting by the first value and then taking greedily fails, because a pair with a small second value should be preferred.
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
- 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?
- How many palindromic substrings (counted by position, so repeated text at different positions counts separately) does "abacabad" have? A…