top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Find the maximum number of vowels in the substring of fixed length?

0 votes
461 views

Write a function which can find the maximum number of vowels out of all the sub-strings which could be formed out of the provided string.

Input:

Maximum length of sub-string: 5
Main String : jondoejumpoverfenceandrun

Output: 3

posted Sep 13, 2020 by Atindra Kumar Nath

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Following code may be helpful -

function is_vowel(c)
{
  switch (c)
  {
    case 'a':
    case 'A':
    case 'e':
    case 'E':
    case 'i':
    case 'I':
    case 'o':
    case 'O':
    case 'u':
    case 'U':
        return true;
    default:
        return false;
  }
}
function count_vowel(str)
{
    var count=0;
    for (var i=0; i < str.length; i++)
    {
        if (is_vowel(str.charAt(i)))
        {
            count++;
        }
    }
    return count;
}

function get_maxvowel(str, substrsize)
{
    var maxvovelsize = 0;
    for(i=0; i < (str.length - substrsize + 1) ; i++)
    {
        if (count_vowel(str.substr(i, substrsize)) > maxvovelsize)
            maxvovelsize = count_vowel(str.substr(i, substrsize));
    }
    return maxvovelsize;
}
answer Sep 13, 2020 by Salil Agrawal
Similar Questions
+4 votes

For example:
If string is "abcd" the output should "abc", "abd", "acd", "bcd".

+1 vote

Given a array of integers there is one that is repeated several time. How would you compute the length of the sequence of repeated elements.

...