Data Structures & AlgorithmsModerateTCS NQT · Infosys
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 remaining array is strictly increasing?
- A. 4
- B. 5
- C. 6
- D. 7
Correct answer: B. 5
The kept elements form a strictly increasing subsequence, so the minimum deletions is n minus the longest strictly increasing subsequence. Counting elements that are out of place with respect to their neighbours gives a different number.
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 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…
- What is the minimum number of cuts needed to split "abbacdcdc" into pieces that are each a palindrome?