Interview Questions/Coding/Vowel Window Load

Vowel Window Load

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Vowel Window Load

A voice system charges every substring according to how many lowercase vowels it contains. The vowels are a, e, i, o, and u. Each vowel occurrence contributes to every substring that includes its position. Consonants add no direct charge, but they may appear inside charged substrings. Input Format: You are given a lowercase string s. Output Format: Return the total vowel charge across all substrings of s.

Examples

Example 1
Input:
s = "aba"
Output:
6

Explanation: Vowel contributions are a@0:3, a@2:3. Their sum is 6, so the output is 6.

Approach hint

A character at index i appears in (i + 1) * (n - i) substrings.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp