Data Structures & AlgorithmsModerateGATE CS · ICPC regional
What is the length of the longest substring of aabbbcca in which every letter occurs at most twice?
- A. 5
- B. 6
- C. 7
- D. 9
Correct answer: A. 5
A sliding window with letter counts, shrinking whenever a letter exceeds two occurrences, finds the longest valid window in linear time.
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 of length 3 or more does racecar contain (counted by position)?
- How many distinct rotations does the string aabaab have (including itself)?
- What is the sum of all positive divisors of 28, a perfect number?
- How many integers in [1, 100] have exactly two distinct prime factors (counted without multiplicity)?
- What is the digital root of 98765 (repeatedly sum the digits until one digit remains)?
- How many ways are there to climb exactly 6 stairs taking steps of size 1, 2 or 4 (different orders of steps count as different ways)?