Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many subsequences of length 3 of the string abcabc are palindromes (distinct index choices count separately)?
- A. 20
- B. 6
- C. 3
- D. 12
Correct answer: B. 6
Fix equal outer letters (a at 0 and 3, b at 1 and 4, c at 2 and 5); the middle must lie strictly between them, giving 2 choices each: 6. Ignoring that the middle must be between them gives 12, 3 counts only the outer pairs and 20 counts all triples.
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 queue holds 1 to 6 in order. The front element is moved to the back, then the front is removed, repeated until one element remains…
- What is the number of integer pairs (x, y) with 1 <= x <= y <= 20 for which gcd(x, y) = 1 and x + y is even?
- How many elements of the array [6, 12, 18, 24, 30] are divisible by at least one element that appears before them in the array?
- From [4, -2, 7, 1, -5, 3, 8, 2], choose a window of 4 consecutive elements, then remove exactly one element from that window. What is the…
- How many index pairs i < j in [5, 2, 8, 3, 1, 9] satisfy a[i] a[j] <= 15?
- What is the sum of the minimum element over all contiguous subarrays of [5, 3, 4, 2] that have length at least 2?