Data Structures & AlgorithmsHardTCS NQT · Codeforces Div2 B
What is the length of the longest substring of "bbaacabaacb" that contains EXACTLY two letters 'a'?
- A. 6
- B. 5
- C. 3
- D. 10
Correct answer: B. 5
Positions of the a's split the string into gaps; the longest valid substring spans from just after one a to just before the a that is two places later. Using a window that allows at most two a's gives a longer, wrong answer.
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
- Choose exactly 4 elements of [6, 1, 9, 4, 7, 2, 8, 5] (by position) such that no two chosen positions are adjacent. What is the maximum…
- How many permutations of 1, 2, 3, 4, 5 have exactly 3 inversions (pairs of positions i < j with p[i] > p[j])?
- What is the minimum number of positive perfect cubes (1, 8, 27, ...) whose sum is exactly 31? Repeats are allowed.
- How many substrings of "abacaxayaba" are palindromes of ODD length at least 3?
- Among all distinct permutations of the letters of "dbca" sorted alphabetically, what is the 1-based position of "dbca" itself?
- List all distinct permutations of the multiset of letters in "aabc" in alphabetical order. What is the 5th string in this list?