Funcia
Tutorialcountingstring

Count the Vowels

Memory limit
256 MB
Correctness time limit
10000 ms
Solvers
0
0

Given a string s of lowercase English letters, return the number of vowels (a, e, i, o, u) in it.

Examples

sresult
"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

  • 1≤1 \le length of s ≤1,000\le 1{,}000
  • s contains only lowercase English letters.

Expected complexity

Time
O(N)
Space
O(1)

Examples

sExpected
"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

LanguageEfficiency time limit
C (GCC, gnu17)200 msestimated
C++ (GCC, gnu++23)200 msderived
Python 3.131000 msderived
Java 251000 msderived
Kotlin 2.4 (JVM)1200 msestimated
C# 14 (.NET 10)1200 msestimated

Test groups

GroupWeightTestsVisibility
sample03inputs and outputs
correctness10012verdict only
Loading editor…
Log in to run or submit code.

No result yet. Run or submit your code.