top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

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

0 votes

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.


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

Output: 3

posted 6 days ago 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;
        return false;
function count_vowel(str)
    var count=0;
    for (var i=0; i < str.length; i++)
        if (is_vowel(str.charAt(i)))
    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 6 days ago 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.

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.