You are given a string s. Write a function to find the longest substring that does not contain any vowels. Please write a function that solves this problem, and explain your algorithm.
Assistant
We are given a string s. We need to find the longest substring that does not contain any vowels.
Substrings are contiguous sequences of characters within the string.
We are to avoid any vowels (assuming both uppercase and lowercase? The problem says "vowels", so we should consider both. Let's assume vowels are 'a', 'e', 'i', 'o', 'u' and their uppercase equivalents).
Approach:
We can iterate through the string and maintain a current substring that has no vowels. When we encounter a vowel, we break the current substring and start a new one from the next character.
However, note that we want the longest substring without vowels. We can do:
Initialize:
longest = "" (or we can keep the length and start index)
current = "" (current substring without vowels)
For each char in s:
if char is not a vowel (case insensitive):
current += char
else:
if len(current) > len(longest):
longest = current
current = "" # reset because we encountered a vowel
After the loop, we need to check the last current because the string might end without a vowel.
But note: what if the entire string has no vowels? Then we never break and we set longest at the end.
Alternatively, we can do without building the entire substring each time to save memory? We can just keep indices.
Let me do with indices:
start = 0 (start of current valid substring)
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] is a vowel:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i+1 # next substring starts after the vowel
After loop, check the last substring from start to end.
Then the substring is s[max_start: max_start+max_len]
However, note: what if there are consecutive vowels? Then we reset start to i+1, and then when we see another vowel, we do the same. But note that between two vowels, the substring is from the previous vowel's next to the current vowel (which is vowel). So that's correct.
But wait, what if the string ends with a consonant? Then after the loop, we have to check from start to the end.
Let me adjust:
start = 0
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i+1
After the loop, we have a substring from start to the end.
But wait, what if the string has no vowels? Then we never set start to anything else, and at the end we set current_len = len(s) - 0 = len(s). That's correct.
However, note: what if the string is empty? Then we should return empty string.
Let's test with a few examples:
Example 1: s = "abcde"
vowels: 'a','e','i','o','u'
At i=0, 'a' is vowel -> current_len = 0-0=0, max_len=0, start=1.
Then i=1, 'b' not vowel -> nothing.
i=2, 'c' not vowel.
i=3, 'd' not vowel.
i=4, 'e' vowel -> current_len = 4-1=3, max_len=3, max_start=1, start=5.
Then after loop, current_len = 5-5=0.
So we return s[1:4] -> "bcd"
Example 2: s = "aeiou"
All vowels. Then at each vowel we set current_len=0 and start to next index. At the end, current_len=0. So return empty string.
Example 3: s = "bcd"
No vowels. Then loop never hits vowel. After loop, current_len=3, so return "bcd".
Example 4: s = "aab"
At i=0, 'a' vowel -> current_len=0, start=1.
i=1, 'a' vowel -> current_len=0, start=2.
i=2, 'b' not vowel.
After loop, current_len=1, so return "b".
But wait, what about the substring between two vowels? In example 4, we have two consecutive vowels. The substring between them is empty? Actually, we are resetting start to i+1 at each vowel. So for two consecutive vowels, we get:
Then at i=2, we are at the end. So the last substring is from index 2 to 2 (length 1). That's correct.
However, note: what if we have a vowel at the beginning and then a non-vowel? We already handled.
But wait, what if we have a vowel at the end? Example: s = "abc"
i=0: 'a' vowel -> current_len=0, start=1.
Then i=1 and i=2 are non-vowels.
After loop, current_len = 3-1=2 -> "bc". That's correct.
However, note: the substring must not contain ANY vowel. So when we see a vowel, we break the current substring and start after it.
But what about the case when the string starts with a vowel? We break at the first vowel and set start to 1. Then we continue.
This algorithm seems to work.
Let's code accordingly.
But note: we have to consider both cases. We can define vowels as a set for O(1) lookup.
However, the problem says "any vowels", so we should consider both cases. Let's define:
vowels = set('aeiouAEIOU')
Steps:
if s is empty, return ""
start = 0
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i + 1
But wait, what if the longest substring is at the very beginning and then we have a vowel? Then we set max_len and max_start at the first vowel. Then we reset start and continue. That's fine.
However, note: what if there are two substrings of the same maximum length? We return the first one? The problem says "the longest substring", so if there are multiple, we can return any? But the above returns the first one.
Let me test with: s = "bcdae"
We want "bcd" (from index0 to 2) and then "ae" are vowels, then after 'e' we have nothing? Actually, the substring without vowels between two vowels? Here we have:
i=0: 'b' not vowel -> current substring: "b"
i=1: 'c' not vowel -> "bc"
i=2: 'd' not vowel -> "bcd"
i=3: 'a' vowel -> break, current_len=3, max_len=3, max_start=0, start=4
i=4: 'e' vowel -> current_len=0, start=5
after loop: current_len=0.
So we return "bcd".
What about s = "bcdafg"?
We have:
i=0,1,2: "bcd"
i=3: 'a' vowel -> break, max_len=3, max_start=0, start=4.
i=4: 'f' not vowel -> current substring: "f"
i=5: 'g' not vowel -> "fg"
Then after loop, current_len=2, which is less than 3, so still "bcd".
But what if we have two substrings of same length? Example: s = "bcdafgh"
First substring: "bcd" (len3)
Then after 'a', we have "fgh" (len3). We want the first one? Our algorithm will return the first one because when we see the second substring, current_len=3 is not greater than max_len (which is 3). So we keep the first.
If we want the last one, we change the condition to >=? But the problem says "the longest", so any is acceptable. However, note that sometimes they want the first occurrence? The problem doesn't specify. But the above returns the first.
However, note: what if the string is all consonants? Then we return the whole string.
Let me adjust for the case when the string is empty.
Code:
def longest_substring_without_vowels(s):
vowels = set('aeiouAEIOU')
if not s:
return ""
code
start = 0
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i + 1
current_len = len(s) - start
if current_len > max_len:
max_len = current_len
max_start = start
return s[max_start: max_start+max_len]
But wait, what if the string has no vowels? Then we never enter the if condition in the loop. So after the loop, we set current_len = len(s) and return the whole string. Correct.
However, there's a subtlety: when we have a vowel at the very first character, then at i=0 we set current_len = 0, and start=1. Then we continue. That's fine.
But what about a string that ends with a vowel? Example: s = "abcde"
We already tested. It returns "bcd", which is correct because after the last vowel 'e', there's no more characters.
What about s = "abcde!"?
Here, after 'e' we have '!', which is not a vowel. So:
At i=4 (vowel 'e'): current_len=4-1=3, max_len=3, max_start=1, start=5.
Then i=5: '!' not vowel -> current substring: "!".
After loop: current_len = 6-5=1 -> not longer.
So we return "bcd".
But wait, what about the substring from index1 to index4? That's "bcd", and then after the vowel we have "!". So the longest is "bcd".
What about s = "ab!cde"?
We have:
i=0: 'a' vowel -> start=1
i=1: 'b' not vowel -> current substring: "b"
i=2: '!' not vowel -> "b!"
i=3: 'c' not vowel -> "b!c"
i=4: 'd' not vowel -> "b!cd"
i=5: 'e' vowel -> break, current_len=5-1=4, so max_len=4, max_start=1, start=6.
Then after loop: current_len=0.
So return "b!cd"
That's correct because it doesn't contain vowels.
However, note: the problem says "substring that does not contain any vowels". So non-alphabet characters are allowed? Yes, because we only break on vowels.
So the algorithm is sound.
But wait, what about performance? We are iterating once, O(n). And we are using a set for vowels, O(1) lookup.
Let me write the code accordingly.
However, note: the problem says "Write a function". So we need to define a function.
Also, we should consider edge cases: empty string, string with only vowels, string with no vowels.
Let me test with:
s = "" -> return ""
s = "aeiou" -> return ""
s = "bcd" -> return "bcd"
s = "a" -> return "" because we break at index0, then after loop current_len=0. So return empty.
s = "b" -> no vowel, so return "b".
For s="a":
i=0: vowel -> current_len=0-0=0, max_len=0, start=1.
then after loop: current_len = 1-1=0 -> max_len=0, so return "".
That's correct because the substring without vowels in "a" is empty.
But wait, what about a single consonant?
s="b":
loop: i=0, 'b' not vowel -> nothing.
after loop: current_len = 1-0=1, so return "b".
So it works.
Let me write the function.
However, note: the problem says "longest substring", so if there are multiple of same length, we return the first one? The above returns the first one. But if we want the last one, we change the condition to >=.
But the problem doesn't specify, so I'll stick to the first one.
Alternatively, we can also do:
code
if current_len >= max_len:
max_len = current_len
max_start = start
Then for s = "bcdafgh", we would get the last one "fgh". But let's stick to the first.
Since the problem statement doesn't specify, I'll keep the condition as > so we get the first.
Let me change to >= if we want the last? But note: when we have two of same length, we want the first one? The problem says "the longest", so either is acceptable. But typically, we return the first occurrence.
However, let me read the problem again: "find the longest substring" - it doesn't specify which one if multiple. So we can choose.
I'll keep the condition as > to return the first.
Code:
def longest_substring_without_vowels(s):
vowels = set('aeiouAEIOU')
if not s:
return ""
code
start = 0
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i + 1
current_len = len(s) - start
if current_len > max_len:
max_len = current_len
max_start = start
return s[max_start: max_start+max_len]
Let me test with s = "bcdaefg"
We have:
substring1: "bcd" (len3) -> max_len=3, max_start=0.
then after 'a', we have "efg"? Wait, 'e' is vowel? Actually, after 'a' we have 'e'? Let's break down:
code
s = "b c d a e f g"
indices:0 1 2 3 4 5 6
i=0: 'b' -> not vowel
i=1: 'c' -> not vowel
i=2: 'd' -> not vowel
i=3: 'a' -> vowel: current_len=3, set max_len=3, max_start=0, start=4.
i=4: 'e' -> vowel: current_len=0 (4-4=0), set start=5.
i=5: 'f' -> not vowel
i=6: 'g' -> not vowel
after loop: current_len=7-5=2 -> not longer.
So we return "bcd".
But note: there is a substring "fg" of length 2, and also after the first vowel we have a substring from index4? But index4 is vowel, so we break. Then from index5 to 6: "fg". That's length 2.
So the longest is "bcd".
Now, what if we have s = "bcdafgh" (as before) ->
i=0,1,2: "bcd"
i=3: 'a' -> break, max_len=3, max_start=0, start=4.
i=4: 'f' -> not vowel
i=5: 'g' -> not vowel
i=6: 'h' -> not vowel
after loop: current_len=7-4=3 -> equal to max_len, so if we use > we don't update. So we return the first.
If we change to >=, then at the end we update and return the last one.
Since the problem doesn't specify, I'll keep >.
However, note: what if the entire string is one long substring without vowels? Then we never set max_len in the loop, and at the end we set max_len to the whole string. That's correct.
Let me write the code accordingly.
But wait, what if the string has a vowel at the very end? Example: s = "bcdae"
We already did: returns "bcd". Correct.
What about s = "bcdae!"?
Same as above, but after 'e' we have '!'. Then:
i=0,1,2: "bcd"
i=3: 'a' -> break, max_len=3, max_start=0, start=4.
i=4: 'e' -> break, current_len=0, start=5.
i=5: '!' -> not vowel.
after loop: current_len=6-5=1 -> not longer.
code
So return "bcd".
What about s = "bcd!ae"?
We have:
i=0,1,2: "bcd"
i=3: '!' -> not vowel -> current substring: "bcd!"
i=4: 'a' -> vowel: current_len=4 (0 to 3) -> 4>3, so max_len=4, max_start=0, start=5.
i=5: 'e' -> vowel: current_len=0, start=6.
after loop: current_len=0.
code
So return "bcd!" (length 4). That's correct.
So the algorithm is working.
However, note: the problem says "substring", so we are returning a contiguous part. We are doing that.
Let me write the function.
But note: the problem says "Write a function", so we need to define it.
I'll write:
def longest_substring_without_vowels(s: str) -> str:
vowels = set('aeiouAEIOU')
if not s:
return ""
code
start = 0
max_len = 0
max_start = 0
for i, char in enumerate(s):
if char in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i + 1
current_len = len(s) - start
if current_len > max_len:
max_len = current_len
max_start = start
return s[max_start: max_start+max_len]
We can also do without the set by using a string and checking in but set is faster.
Let me test with a few more:
Example: s = "a" -> returns ""
Example: s = "b" -> returns "b"
Example: s = "ab" -> returns "b"
Example: s = "ba" -> returns "b"
Example: s = "ae" -> returns ""
Example: s = "aeb" -> returns "b"
All seem correct.
However, note: what if the string has uppercase vowels? Our set includes both.
Example: s = "A" -> returns "" because 'A' in set.
So it's case-insensitive.
Now, what about non-English letters? The problem says "vowels", so we assume English vowels.
We are done.
But wait, the problem says "any vowels", so we break on any vowel. We are doing that.
Let me think if there is any edge case: what if the string has a vowel that is not in the set? We assume only English vowels.
So the function is:
def longest_substring_without_vowels(s):
vowels = set('aeiouAEIOU')
if not s:
return ""
code
start = 0
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i + 1
current_len = len(s) - start
if current_len > max_len:
max_len = current_len
max_start = start
return s[max_start: max_start+max_len]
Alternatively, we can use a while loop and two pointers? This is already one pass.
But note: we are not using extra space except for a few variables.
This is O(n) time and O(1) space (if we don't count the set of vowels, which is fixed).
We are good.
However, note: what if the string is very long? We are using integer indices and slicing at the end. Slicing creates a new string of length max_len. That's acceptable because we have to return the substring.
So we are done.
Let me write the explanation:
Algorithm:
We traverse the string with a pointer i and maintain a start pointer that marks the beginning of the current substring without vowels.
When we encounter a vowel at index i, we compute the length of the current valid substring (from start to i-1). If this length is greater than the maximum found so far, we update the maximum length and the starting index.
Then we set start to i+1 because the next substring will start after this vowel.
After the loop, we check the last substring from start to the end of the string.
Finally, we return the substring from max_start of length max_len.
This works because we are essentially breaking the string at every vowel and then considering the segments between vowels (and the beginning and end) as candidates.
Time Complexity: O(n) where n is the length of the string.
Space Complexity: O(1) additional space (excluding the output and the fixed set of vowels).
Let me test with the example: s = "The quick brown fox jumps over the lazy dog"
We want the longest substring without vowels. Let's see:
Breaking at vowels:
The -> vowel at index0, so first segment is empty.
then from index1: "he q" -> wait, let's break:
code
So the algorithm is working.
Now, what if we want the substring to be returned in the original case? We are returning the substring as is.
We are done.
Let me write the code accordingly.
However, note: the problem says "Write a function", so we need to output the function.
I'll write:
def longest_substring_without_vowels(s):
vowels = set('aeiouAEIOU')
if not s:
return ""
start = 0
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i + 1
current_len = len(s) - start
if current_len > max_len:
max_len = current_len
max_start = start
return s[max_start: max_start+max_len]
But wait, what if the string has a vowel at the very beginning and then a long substring? We break at the first vowel and then start from 1. That's correct.
One more: s = "apple" ->
i=0: 'a' vowel -> current_len=0, start=1.
i=1: 'p' not vowel
i=2: 'p' not vowel
i=3: 'l' not vowel
i=4: 'e' vowel -> current_len=4-1=3, max_len=3, max_start=1, start=5.
after loop: current_len=0.
return "ppl"
Correct.
Now, what about s = "APPLE"?
A is vowel, then P, P, L, E -> same, returns "PPL".
So we are good.
However, note: what if the string has a vowel that is not in the set? Then we don't break. But we assume only English vowels.
We are done.
Let me write the explanation in the response.
But note: the problem says "explain your algorithm". So I'll write:
Algorithm:
We define a set of vowels (both lowercase and uppercase). Then we traverse the string with an index i.
We maintain a start pointer that indicates the start of the current substring without vowels.
For each character at index i:
If the character is a vowel, then the current substring (from start to i-1) is a candidate. We compare its length with the maximum found so far and update if necessary.
Then we set start to i+1 because the next substring must start after this vowel.
After the loop, we check the last substring from start to the end of the string.
Finally, we return the substring that starts at max_start and has length max_len.
This algorithm runs in O(n) time and uses O(1) extra space.
Now, I'll write the function accordingly.
But wait, what if the string is very long and we are concerned about the set lookup? It's O(1) because the set has fixed size (10 characters). So it's fine.
We are done.
However, note: the problem says "substring", so we are returning a contiguous sequence. We are doing that.
One more edge: what if the string has no vowels and is very long? Then we traverse once and then return the whole string. That's O(n).
We are good.
Let me write the code with type hints for clarity.
Since the problem doesn't specify the language, I'll assume Python.
Code:
def longest_substring_without_vowels(s: str) -> str:
vowels = set('aeiouAEIOU')
if not s:
return ""
start = 0
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i + 1
current_len = len(s) - start
if current_len > max_len:
max_len = current_len
max_start = start
return s[max_start: max_start+max_len]
That's the function.
Now, I'll provide the explanation as required.
But note: the problem says "You are given a string s. Write a function to find the longest substring that does not contain any vowels."
So we are done.
However, note: the problem might be expecting to return the substring, not the length. So we return the substring.
Let me test with the example from the problem? There is no example given.
But we have tested with several.
I think it's correct.
One more: s = "a" -> returns "" (empty string) because the substring without vowels is empty.
But wait, what about the empty substring? The problem says "substring", and empty string is a substring. But typically, we might want the longest non-empty? However, if the string has only vowels, then the longest substring without vowels is the empty string. So we are returning empty string.
That's acceptable.
However, note: what if the string is empty? We return empty.
So we are consistent.
Now, what if the string has a single vowel? Then we return empty.
So we are returning the longest substring without vowels, which might be empty.
But sometimes the problem expects at least one character? The problem says "longest substring", so if there are no non-vowel characters, then the empty substring is the only one.
Alternatively, we might want to return the empty string? Yes.
So we are good.
I'll now write the final answer.
To solve this problem, we need to find the longest contiguous substring in a given string that does not contain any vowels (both lowercase and uppercase). The solution involves efficiently scanning the string while keeping track of the current and longest valid substrings.
Approach
Initialization: Define a set of vowels for O(1) lookups. Handle edge cases where the input string is empty.
Tracking Substrings: Use two pointers:
start: Marks the beginning of the current substring without vowels.
Iterate through each character in the string. When a vowel is encountered:
Calculate the length of the current valid substring (from start to the previous character).
Update the longest substring if the current one is longer.
Reset start to the next character after the vowel.
Final Check: After the loop, check the substring from the last start to the end of the string.
Result Extraction: Return the longest substring found using the stored start index and length.
This approach ensures a single pass through the string, making it efficient with O(n) time complexity and O(1) additional space (excluding the fixed vowel set).
Solution Code
python
def longest_substring_without_vowels(s: str) -> str:
vowels = set('aeiouAEIOU')
if not s:
return ""
start = 0
max_len = 0
max_start = 0
for i in range(len(s)):
if s[i] in vowels:
current_len = i - start
if current_len > max_len:
max_len = current_len
max_start = start
start = i + 1
current_len = len(s) - start
if current_len > max_len:
max_len = current_len
max_start = start
return s[max_start: max_start + max_len]
Explanation
Vowel Set: A set of all vowels (both cases) is used for quick membership checks.
Pointers:
start tracks the beginning of the current non-vowel substring.
max_start and max_len store the starting index and length of the longest valid substring found.
Loop: For each character:
If it’s a vowel, the current substring (from start to the previous index) is evaluated. If longer than the current maximum, update max_start and max_len. Then move start past the vowel.
Final Segment: After the loop, check the substring from the last start to the string's end, as it might be the longest.
Result: Slice the original string using max_start and max_len to return the longest vowel-free substring.
This method efficiently processes the string in one pass, ensuring optimal performance while correctly identifying the longest substring without any vowels.
Actually, let's break by vowels:
T h e q u i c k b r o w n f o x j u m p s o v e r t h e l a z y d o g
Vowels: e, u, i, o, u, o, e, e, a, o
So the segments without vowels are:
after 'e' (at index2) until next vowel:
from index3: " q" -> but wait, index3 is space? Then we have " q" until 'u' at index5? Actually, let's index:
s = "The quick brown fox jumps over the lazy dog"
indices: 0:T,1:h,2:e,3: ,4:q,5:u,6:i,7:c,8:k,9: ,10:b,11:r,12:o,13:w,14:n,15: ,16:f,17:o,18:x,19: ,20:j,21:u,22:m,23:p,24:s,25: ,26:o,27:v,28:e,29:r,30: ,31:t,32:h,33:e,34: ,35:l,36:a,37:z,38:y,39: ,40:d,41:o,42:g
Vowels at: 2(e),5(u),6(i),12(o),17(o),21(u),26(o),28(e),33(e),36(a),41(o)
So the segments:
[0,2) -> "Th" (but note: we break at the vowel, so from 0 to 1? Actually, we break at index2 (vowel) so the segment is from start=0 to i=2 -> [0,2) which is "Th". Then start=3.
Then from 3 to 5: [3,5) -> " q" (space and q) -> but wait, at i=5 (vowel) we break. So that's 2 characters.
Then from 6? Actually, after vowel at 5, we set start=6. But then at i=6 we have vowel again. So [6,6) -> empty.
Then start=7. Then until next vowel at 12: [7,12) -> "ck br" (indices7-11) -> that's 5 characters: 'c','k',' ','b','r' -> "ck br"
Then start=13, until vowel at 17: [13,17) -> "wn f" -> 4 characters? Wait, 13:w,14:n,15: ,16:f -> that's 4.
Then start=18, until vowel at 21: [18,21) -> "x j" -> 3 characters? 18:x,19: ,20:j -> 3.
Then start=22, until vowel at 26: [22,26) -> "mps " -> 4 characters? 22:m,23:p,24:s,25:space -> 4.
Then start=27, until vowel at 28: [27,28) -> "v" -> 1.
Then start=29, until vowel at 33: [29,33) -> "r t h" -> 4? 29:r,30:space,31:t,32:h -> 4.
Then start=34, until vowel at 36: [34,36) -> " l" -> 2? 34:space,35:l -> 2.
Then start=37, until vowel at 41: [37,41) -> "zy d" -> 4? 37:z,38:y,39:space,40:d -> 4.
Then after last vowel at 41, we have from 42 to end: [42,43) -> "g" -> 1.
So the longest segments are of length 5: "ck br" and maybe others? Actually, we have two of length 5? Wait, we have one of length 5: "ck br". But wait, let's count:
"Th" -> 2
" q" -> 2
"" -> 0
"ck br" -> 5 (c,k,space,b,r) -> 5
"wn f" -> 4
"x j" -> 3
"mps " -> 4
"v" -> 1
"r t h" -> 4
" l" -> 2
"zy d" -> 4
"g" -> 1
So the longest is 5: "ck br"
But wait, what about the segment from index7 to 12? That's indices7,8,9,10,11 -> 5 characters. So that's the longest.
Our algorithm should return that.
Let's simulate:
start=0
i=0: 'T' not vowel -> nothing
i=1: 'h' not vowel
i=2: 'e' vowel -> current_len=2-0=2, max_len=2, max_start=0, start=3.
i=3: ' ' not vowel
i=4: 'q' not vowel
i=5: 'u' vowel -> current_len=5-3=2, not longer, start=6.
i=6: 'i' vowel -> current_len=0, start=7.
i=7: 'c' not vowel
i=8: 'k' not vowel
i=9: ' ' not vowel
i=10: 'b' not vowel
i=11: 'r' not vowel
i=12: 'o' vowel -> current_len=12-7=5, max_len=5, max_start=7, start=13.
... and then we continue but none longer than 5.
After loop, the last segment from 42 to 43 is length 1, so we return s[7:12] -> indices7 to 11 -> "ck br" (without the 'o').
That's correct.