EasyFoundational
Count Vowels in a String
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 15 min
- Programming Fundamentals
Description
Given a string s, count how many vowels it contains.
The English vowels are a, e, i, o, and u. Both uppercase and lowercase vowels must be counted. Every occurrence is counted separately; for example, the string "education" contains five vowels.
All input characters are standard English letters and spaces. An empty string contains zero vowels.
Examples:
s = "Hello World"returns3.s = "AEIOU"returns5.s = "rhythm"returns0.
Implement countVowels(s).
Constraints
0 <= s.length <= 100000 s contains only uppercase English letters, lowercase English letters, and spaces.
Sample cases
3Sample 1
Input
s = "Hello World"
Expected output
3
Sample 2
Input
s = "AEIOU"
Expected output
5
Sample 3
Skills and languages
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer