Skip to main content
Back to problems
#2586
Easy Algorithms

Count the number of vowel strings in range

Array String Counting
74.2% acceptance
Feb 25, 2026
378
32
You are given a 0-indexed array of string words and two integers left and right. A string is called a vowel string if it starts with a vowel character and ends with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'. Return the number of vowel strings words[i] where i belongs to the inclusive range [left, right].

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn vowel_strings(words: Vec<String>, left: i32, right: i32) -> i32 {
    // You are given a 0-indexed array of string words and two integers left and right.
    // A string is called a vowel string if it starts with a vowel character and ends
    // with a vowel character where vowel characters are 'a', 'e', 'i', 'o', and 'u'.
    // Return the number of vowel strings words[i] where i belongs to the inclusive range [left, right].
    let is_vowel = |c: char| matches!(c, 'a' | 'e' | 'i' | 'o' | 'u');
    words[(left as usize)..=(right as usize)]
      .iter()
      .filter(|w| {
        let mut chars = w.chars();
        let first = chars.next().unwrap();
        let last = w.chars().last().unwrap();
        is_vowel(first) && is_vowel(last)
      })
      .count() as i32
  }
}