Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

What is the length of the longest substring of "aebcdiouxyab" in which the number of vowels (a, e, i, o, u) equals the number of non-vowels?

  1. A. 14
  2. B. 12
  3. C. 10
  4. D. 6

Correct answer: B. 12

Map each vowel to +1 and each other letter to −1; a substring is balanced when its prefix balances are equal, so the longest gap between equal prefix balances gives the answer. Counting only vowels in the window (without the balance) does not measure equality.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic