Knowee
Questions
Features
Study Tools

Given a string S consisting of only lowercase characters, find the length of the longest substring that does not contain any vowel.Input FormatFirst line of input contains T - number of test cases. Its followed by T lines, each line contains a string of size N, containing only lowercase english alphabets.Output FormatFor each test case, print the length of the largest substring that does not contain any vowel, separated by newline.Constraints1 <= T <= 1001 <= N <= 104Example

Question

Given a string S consisting of only lowercase characters, find the length of the longest substring that does not contain any vowel.Input FormatFirst line of input contains T - number of test cases. Its followed by T lines, each line contains a string of size N, containing only lowercase english alphabets.Output FormatFor each test case, print the length of the largest substring that does not contain any vowel, separated by newline.Constraints1 <= T <= 1001 <= N <= 104Example

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python solution for the problem:

def longest_substring_without_vowel(T, strings):
    vowels = 'aeiou'
    results = []
    for i in range(T):
        S = strings[i]
        max_length = 0
        current_length = 0
        for char in S:
            if char not in vowels:
                current_length += 1
                if current_length > max_length:
                    max_length = current_length
            else:
                current_length = 0
        results.append(max_length)
    return results

This function takes two arguments: T which is the number of test cases and strings which is a list of strings. For each string, it iterates over each character. If the character is not a vowel, it increments the current length of the substring without vowels. If this length is greater than the maximum length found so far, it updates the maximum length. If the character is a vowel, it resets the current length to 0. Finally, it returns a list of the maximum lengths for each string.

Here is how you can use this function:

T = 2
strings = ['abcde', 'fghij']
print(longest_substring_without_vowel(T, strings))

This will output [1, 5] because the longest substring without vowels in 'abcde' is 'b' with length 1 and in 'fghij' is 'fghij' with length 5.

This problem has been solved

Similar Questions

Given 2 strings A and B, find the smallest substring of B having all the characters of A, in any order.Input FormatThe first line of input contains T - the number of test cases. It's followed by T lines, each line containing 2 space-separated strings - A and B.Output FormatFor each test case, print the length of the smallest substring of B having all the characters of A, separated by newline. If no such substring is found, print -1.Constraints20 points1 <= T <= 1001 <= size(A), size(B) <= 10060 points1 <= T <= 1001 <= size(A), size(B) <= 1000120 points1 <= T <= 1001 <= size(A), size(B) <= 10000General Constraints'a' <= A[i], B[i] <= 'z'ExampleInput4fkqyu frqkzkruqmfqyuzlkygonmwvytbytn uqhmfjaqtgngcwkuzyamnerphfmwbloets lwbcrsfothplxseplrtbshbtstjloxsfdzpd dclzztpjldkndgbdqqzmbpOutput7-1139ExplanationTest Case 1:The smallest substring containing all characters of A is "fqyuzlk", which has a length of 7.Test Case 2:Despite considering all possible substrings of B, we cannot find any substring containing all characters of A.Test Case 3:The smallest substring containing all characters of A is "bcrsfothplxse", which has a length of 13.Test Case 4:The smallest substring containing all characters of A is "ztpjldknd", which has a length of 9.

Given a string s, find the length of the longest substring without repeating characters.

Words, Vowels and ConsonantsProblemSubmissionsLeaderboardGiven a sentence containing only uppercase/lowercase english alphabets and spaces, you have to count the number of words, vowels and consonants.Input FormatFirst line of input contains T - number of test cases. Its followed by T lines, each line contains a single sentence.Constraints1 <= T <= 10001 <= len(sentence) <= 104Output FormatFor each test case, print the number of words, vowels and consonants, separated by newline.Sample Input 04HiHello World Exception Hi thereSample Output 01 1 12 3 71 4 52 3 4

Splitting StringGiven a string, find the minimum number of cuts needed to obtain a perfect string. A perfect string is a string that has only a single type of character. Example: aaaaa. A cut in the string should be done exactly in the middle dividing the string into two equal halves.Input FormatThe first line of input contains T - the number of test cases. It is followed by T lines, each line contains a single string consisting only of lowercase English alphabets.Output FormatFor each test case, print the minimum number of cuts required to get a perfect string, separated by a new line. If it is not possible to obtain a perfect string print -1.Constraints1 <= T <= 1031 <= len(str) <= 104ExampleInput2aacabbaaabOutput21ExplanationTest Case 1Cut-1: [aaca][bbaa], Cut-2: [bb][aa]Test Case 2Cut-1: [a][b]

Longest Substring Without Repeating Characters

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.