Count Vowels in String

Quick Overview

Given a string of printable ASCII characters, count how many of its characters are vowels, with uppercase and lowercase letters both counted. It tests basic string traversal, case handling, and stating time and space complexity for inputs up to 100,000 characters.

Count Vowels in String

Company: Crowdstrike

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given a string `s`, return the number of vowels in the string. Vowels are the characters `'a'`, `'e'`, `'i'`, `'o'`, `'u'`, in both uppercase and lowercase. ### Function Signature ```python def count_vowels(s: str) -> int: ... ``` ### Rules - The ten vowel characters are `a`, `e`, `i`, `o`, `u`, `A`, `E`, `I`, `O`, `U`. The letter `y` is not a vowel. - Every other character (consonants, digits, spaces, punctuation) adds nothing to the count. ### Constraints - `1 <= len(s) <= 10^5` - `s` consists of printable ASCII characters. ### Examples ```text Input: s = "hello world" Output: 3 ``` The vowels in "hello world" are `e`, `o` and `o`, so the count is 3. The space and the consonants are ignored. ```text Input: s = "AEIOUaeiou" Output: 10 ``` Every character is a vowel (5 uppercase and 5 lowercase), so the count is 10. ```text Input: s = "Why try?" Output: 0 ``` The string has no `a`, `e`, `i`, `o` or `u` in either case. Neither `y` counts, because `y` is not a vowel here.

Overview: Given a string of printable ASCII characters, count how many of its characters are vowels, with uppercase and lowercase letters both counted. It tests basic string traversal, case handling, and stating time and space complexity for inputs up to 100,000 characters.

Crowdstrike logo
Crowdstrike
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given a string s, return the number of vowels in the string.

Vowels are the characters 'a', 'e', 'i', 'o', 'u', in both uppercase and lowercase.

Function Signature

def count_vowels(s: str) -> int:
    ...

Rules

  • The ten vowel characters are a , e , i , o , u , A , E , I , O , U . The letter y is not a vowel.
  • Every other character (consonants, digits, spaces, punctuation) adds nothing to the count.

Constraints

  • 1 <= len(s) <= 10^5
  • s consists of printable ASCII characters.

Examples

Input: s = "hello world"
Output: 3

The vowels in "hello world" are e, o and o, so the count is 3. The space and the consonants are ignored.

Input: s = "AEIOUaeiou"
Output: 10

Every character is a vowel (5 uppercase and 5 lowercase), so the count is 10.

Input: s = "Why try?"
Output: 0

The string has no a, e, i, o or u in either case. Neither y counts, because y is not a vowel here.