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 <= 104ExampleInput3smartinterviewsalgorithmssearchingOutput243ExplanationTest Case 1:We have multiple substrings of length 2 which doesn't contain any vowels: "sm", "rt", "nt", "rv", "ws"Test Case 2:We have a substring of length 4 which doesn't contain any vowels: "thms"Test Case 3:We have a substring of length 3 which doesn't contain any vowels: "rch"
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 <= 104ExampleInput3smartinterviewsalgorithmssearchingOutput243ExplanationTest Case 1:We have multiple substrings of length 2 which doesn't contain any vowels: "sm", "rt", "nt", "rv", "ws"Test Case 2:We have a substring of length 4 which doesn't contain any vowels: "thms"Test Case 3:We have a substring of length 3 which doesn't contain any vowels: "rch"
Solution
Here is a Python solution for the problem:
def longest_substring_without_vowel(T, strings):
vowels = 'aeiou'
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
print(max_length)
# Test the function
longest_substring_without_vowel(3, ['smartinterviews', 'algorithms', 'searching'])
This function works by iterating over each character in the string. If the character is not a vowel, it increments a counter (current_length). If the counter is greater than the maximum length found so far (max_length), it updates max_length. If the character is a vowel, it resets the counter. After iterating over all characters, it prints the maximum length found.
In the test case, it prints 2, 4, and 3, which are the lengths of the longest substrings without vowels in 'smartinterviews', 'algorithms', and 'searching', respectively.
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.
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
Given a string s, find the length of the longest substring without repeating characters.
3smartinterviewsalgorithmssearchingOutput243ExplanationTest Case 1:We have multiple substrings of length 2 which doesn't contain any vowels: "sm", "rt", "nt", "rv", "ws"Test Case 2:We have a substring of length 4 which doesn't contain any vowels: "thms"Test Case 3:
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]
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.