Im having difficulty finding an algorithm for the following puzzle-
A string is called ugly if it has 3 vowels in a row, or 5 consonants in a row, or both. A string is called nice if it is not ugly. You are given a string s, consisting of uppercase letters (‘A’-‘Z’) and question marks (‘?’).
Can you find an algorithm that tells if the string can be made nice by substituting the question marks with alphabets?
Example –
-
“EE?FFFF” – Cant be made nice. Inserting either a consonant or a vowel would make it ugly.
-
“H??LOWOR??” – Can be made nice.
P.S – Not homework, but a part of a programming puzzle on the internet.
Note that the only strings that might potentially be ugly are those that are already ugly by virtue of the given letters or those which contain only singleton question marks. Here’s the sketch of the proof:
So, we’re left with two simple cases.