Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
What is the length of the longest palindromic subsequence of "bbbab"?
- A. 5
- B. 4
- C. 3
- D. 2
Correct answer: B. 4
Taking the b's around the a gives "bbbb" which is a palindrome of length 4. Substrings alone would give a shorter answer, but subsequences may skip characters.
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
- Trains arrive at times 2, 4, 4, 6, 8 and depart at 3, 5, 7, 6, 9 (a departure at the same time as an arrival frees its platform first)…
- What is the sum of the positive divisors of 60 that are at most 10?
- In how many ways can a product of four matrices A B C D be fully parenthesised (by choosing the order of multiplication)?
- For the histogram [2, 1, 2], each bar i has a maximal rectangle width wi: the number of consecutive bars around i (including i) that are…
- How many distinct value pairs (x, y) with x < y satisfy x + y = 6 among the values in [1, 2, 3, 4, 5, 5, 1]?
- What is the minimum number of cuts needed to split "racecarxyz" into pieces that are all palindromes?