Data Structures & AlgorithmsHardGATE CS · TCS NQT
How many index pairs i < j in "aabb" give a palindromic subsequence of length 2 (that is, s[i] = s[j])?
- A. 3
- B. 2
- C. 1
- D. 12
Correct answer: B. 2
A length-2 palindrome subsequence needs two equal letters, so count equal pairs of positions. The answer is 2 from the pair of a's and the pair of b's.
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
- How many distinct value pairs (x, y) with x < y satisfy x + y = 10 among the values of [1, 2, 3, 4, 5, 6, 7, 8, 9, 5]?
- Smallest value of the maximum block sum when [4, 8, 2, 9, 3, 6] is split into 3 contiguous blocks?
- Using each of [1, 2, 4, 16] at most once, what is the smallest positive integer that cannot be written as a sum of distinct elements of…
- What is the exponent of 3 in the prime factorisation of 30!?
- Items of size 6, 5, 4, 3, 2 must be packed into bins of capacity 10 using first-fit decreasing. How many bins are used?
- How many substrings of "abcabc" are anagrams of "abc" (that is, have the same letters with the same counts)?