Data Structures & AlgorithmsHardGATE CS · ICPC regional
What is the length of the longest substring of aabccbb that can be made into a string of one repeated letter by replacing at most 2 characters?
- A. 4
- B. 5
- C. 6
- D. 7
Correct answer: B. 5
The classic window condition is length minus the maximum frequency in the window being at most k. The window never needs to shrink for a longer valid window to appear.
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 substrings of abcabc contain all of the three letters a, b and c at least once?
- How many substrings of aabacbebebe contain exactly two distinct characters?
- How many substrings of abcdabcabd are anagrams of the pattern abd (same letters with the same multiplicities)?
- How many contiguous subarrays of [1, 2, 2, 3, 1, 1] contain no two adjacent equal elements?
- What is the length of the shortest contiguous subarray of [2, -1, 2, 4, -3, 5] whose sum is at least 7?
- What is the minimum number of characters that must be deleted from aaaabbbbcccdd so that no two letters occur the same number of times?