Your question is Haiku Substring With Syllables. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Faire's product and content surfaces sometimes process short text where a poetic 5-7-5 structure is meaningful. Given a whitespace-separated string, return the first contiguous substring whose three consecutive phrases contain exactly 5, 7, and 5 syllables.
A substring must begin and end on word boundaries. Search from left to right by starting word index. Return the candidate with the smallest starting index, and return the empty string if no candidate exists.
For this problem, count syllables in each word using this deterministic rule: lowercase the word, count contiguous groups of aeiouy, subtract one if the word ends in e and has more than one group, and return at least one syllable per word. Words contain only alphabetic characters and optional apostrophes.
text, a string containing zero or more whitespace-separated words."" if none exists.def first_haiku_substring(text):