Data Structures & AlgorithmsModerateGATE CS · TCS NQT
What is the length of the longest substring of aabaaccaa that contains at most two letters 'a'?
- A. 5
- B. 6
- C. 7
- D. 9
Correct answer: A. 5
Use a sliding window that counts a's and shrinks when a third a enters. Counting only the other letters would give a different window.
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 palindromic substrings (counted by position) does the string abbaabba contain?
- How many distinct palindromic substrings does the string aabaa contain?
- What is the smallest integer x greater than 100 with x congruent to 3 modulo 7 and x congruent to 5 modulo 11?
- How many integers in [1, 200] are coprime to 210?
- What is the sum of all integers in [1, 50] that are either perfect squares or perfect cubes?
- What is the greatest common divisor of 6, 24, 60, 120 and 210?