Tutorialcountingstring
Count the Vowels
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Given a string s of lowercase English letters, return the number of vowels (a, e, i, o, u) in it.
Examples
| s | result |
|---|---|
"hello" | 2 |
"rhythm" | 0 |
"aeiou" | 5 |
Example 1 — e and o: 2.
Example 2 — No vowels at all.
Example 3 — All five letters are vowels.
This is a tutorial problem: there are no performance tests, just return the correct value.
Function signature
solution(s: string) → int
Constraints
- length of
s scontains only lowercase English letters.
Expected complexity
- Time
- O(N)
- Space
- O(1)
Examples
| s | Expected |
|---|---|
"hello" | 2 |
"rhythm" | 0 |
"aeiou" | 5 |
Hint
Hint
For each character check whether it is one of the five vowels, either with ch == 'a' || ch == 'e' || ... or by
looking it up in "aeiou" (ch in "aeiou" in Python, "aeiou".indexOf(ch) >= 0 in Java).
Time limits per language
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1000 ms | derived |
| Kotlin 2.4 (JVM) | 1200 ms | estimated |
| C# 14 (.NET 10) | 1200 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 100 | 12 | verdict only |