โ† Amazon questions

Largest substring containing vowels in even counts

Filed under Amazon

Free read 1 of 3

Use a 5-bit integer where each bit represents the parity (odd/even) of a specific vowel.

The question

Find the length of the longest substring containing an even count of each vowel (a, e, i, o, u). If multiple exist, return all of them.

Constraints

  • String contains only lowercase English letters
  • Length up to 10^5
  • Vowels: a, e, i, o, u

Examples

Input
eleetminicoworo
Output
7
Why
The substring 'eetmini' has 2 'e', 2 'i', 1 'a' (Wait, counts must be even).

Approach

  1. Use a 5-bit integer where each bit represents the parity (odd/even) of a specific vowel.

Tips

  • What they are testing: Use a bitmask to represent the parity of vowel counts.
  • Common mistake: Re-calculating counts for every substring instead of using prefix XOR/bitmask.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.