Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
What is the length of the longest substring of "aabbaacc" in which every letter appears at most twice?
- A. 6
- B. 8
- C. 2
- D. 3
Correct answer: A. 6
Shrink the window when a letter's count exceeds two: 'aabbaa' fails (four a's), but 'bbaacc' (indices 2–7) is valid, length 6. 8 is the whole string, 2 allows each letter at most once, and 3 is a short window such as 'aab'.
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
- What is the sum of the integers from 1 to 100 inclusive that are not perfect squares?
- Sum the largest power of two that divides each element of [12, 40, 7, 24]. What is the total?
- On a 3 by 3 grid, how many unordered pairs of distinct cells share a row or a column?
- What is the length of the longest run of equal consecutive values in [5, 5, 5, 6, 6, 5, 5, 5, 5]?
- How many length-2 substrings of "abbaabab" are either "ab" or "ba"?
- From task sizes [4, 5, 6, 3], what is the largest number of tasks you can keep so that their total size is at most 10?