Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Program to find longest substring of all vowels in order in Python
Suppose we have a string s with only English vowels, we have to find the length of the longest beautiful substring of s. If we cannot find such substring then, return 0. A string is said to be beautiful if it satisfies the following conditions −
Each of the 5 vowels must appear at least once in it.
Letters must be sorted in alphabetical sequence
So, if the input is like s = "aaioaaaaeiiouuooaauu", then the output will be 10 because the substring is "aaaaeiiouu" which is beautiful.
To solve this, we will follow these steps −
vowels := a list of all vowels ['a', 'e', 'i', 'o', 'u']
l := 0, r := 0, longest := 0
-
while l
valid := True
-
for each vowel in vowels, do
valid := valid is true and (r
-
while r
r := r + 1
-
if valid is true, then
longest := maximum of longest and (r - l)
l := r
return longest
Example
Let us see the following implementation to get better understanding −
def solve(s): vowels = ['a', 'e', 'i', 'o', 'u'] l, r, longest = 0, 0, 0 while (lInput
"aaioaaaaeiiouuooaauu"Output
10
