Skip to main content

Command Palette

Search for a command to run...

Count Vowel Substrings of a String

Published
1 min read
Count Vowel Substrings of a String
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

A substring is a contiguous (non-empty) sequence of characters within a string.

A vowel substring is a substring that only consists of vowels ('a', 'e', 'i', 'o', and 'u') and has all five vowels present in it.

Given a string word, return the number of vowel substrings in word.

LeetCode Problem - 2062

class Solution {
    // This method counts the number of vowel substrings in the given word
    public int countVowelSubstrings(String word) {
        int answer = 0;
        int length = word.length();

        // Iterate over each character in the word
        for (int i = 0; i < length; i++) {
            Map<Character, Integer> count = new HashMap<>(); // Map to keep track of vowel counts

            // Iterate from the current character to the end of the word
            for (int j = i; j < length && isVowel(word.charAt(j)); j++) {
                // Count the occurrences of each vowel
                count.put(word.charAt(j), count.getOrDefault(word.charAt(j), 0) + 1);
                // If all 5 vowels are present, increment the answer
                if (count.size() == 5) answer++;
            }
        }
        return answer; // Return the total count of vowel substrings
    }

    // This method checks if a character is a vowel
    public boolean isVowel(char c) {
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.