Data Structures & AlgorithmsHardGATE CS · Infosys
What is the length of the longest palindromic subsequence of the word character?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
The subsequence need not be contiguous; the DP recurrence takes the best of dropping either end when the ends differ. Confusing this with the longest palindromic substring gives a smaller value.
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
- A backspace text editor reads the string a##b#cd# where each # deletes the previous character if one exists. How many characters remain in…
- How many non-empty contiguous subarrays of [6, 10, 15, 7] have gcd equal to 1?
- What is the sum of gcd(a[i..j]) over all contiguous subarrays of [4, 6, 8, 12]?
- How many index pairs i < j have gcd(a[i], a[j]) = 1 for the array [2, 3, 4, 5, 6, 9]?
- What is the sum of lcm(a[i], a[i+1]) for consecutive pairs of the array [2, 3, 4, 6, 9]?
- How many integers x in the range 1 to 1000 are divisible by 3 and have a digit sum divisible by 7?