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 <= 104

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 <= 104

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

Solution

Here is a step-by-step solution in Python:

  1. First, we need to define the vowels. In English, the vowels are 'a', 'e', 'i', 'o', 'u'. We can store them in a set for faster lookup.
vowels = set('aeiou')
  1. Next, we need to iterate over the string and keep track of the longest substring without vowels. We can do this by maintaining a counter for the current length of the substring without vowels, and a variable for the maximum length found so far.
def longest_substring_without_vowels(s):
    vowels = set('aeiou')
    max_length = 0
    current_length = 0

    for char in s:
        if char not in vowels:
            current_length += 1
            max_length = max(max_length, current_length)
        else:
            current_length = 0

    return max_length
  1. Finally, we need to read the input and output the results. The input format specifies that the first line contains the number of test cases, and each subsequent line contains a string. We can read this using the input function in a loop.
T = int(input())
for _ in range(T):
    s = input()
    print(longest_substring_without_vowels(s))

This program will read the number of test cases, then for each test case, read a string, compute the length of the longest substring without vowels, and print the result.

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.