Search code examples
stringalgorithmlanguage-agnostic

Algorithm to get count of distinct vowels in a word


What could be the best algorithm to check if an English word contains at least 2 vowels in it. P.S - Irrespective of any programming language.


Solution

    1. Write a function to check if something is a vowel.
    2. Create a map from vowels to counts, initialized to zeroes.
    3. Iterate through the word one character at a time. If a character is a vowel (using function in 1), then increment the counter associated with that vowel.
    4. Iterate through the map and if there are at least two nonzero values, return true.