Find the First Contiguous Haiku
Updated
Problem statement
Given a sentence, a dictionary of normalized words, and their positive syllable counts, return the first contiguous segment that forms a 5-7-5 haiku.
Split the sentence on ASCII whitespace. For dictionary lookup, lowercase each token and strip surrounding punctuation while preserving internal apostrophes. Return three strings made from the original tokens, preserving spelling and punctuation. Choose the smallest starting token index whose cumulative syllable boundaries are exactly 5, 12, and 17. Return an empty array when no such segment exists.
Function
findFirstHaiku(sentence: String, words: String[], syllables: int[]) → String[]Examples
Example 1
sentence = "Noise, a quiet old pond a frog jumps in sound again."words = ["noise","a","quiet","old","pond","frog","jumps","in","sound","again"]syllables = [2,1,2,1,1,1,1,1,1,2]return = []This input does not reach a final five-syllable line, so no complete haiku exists and the returned array is empty.
Example 2
sentence = "Bright sun over hills soft rain touches green leaves calm winds carry birds home"words = ["bright","sun","over","hills","soft","rain","touches","green","leaves","calm","winds","carry","birds","home"]syllables = [1,1,2,1,1,1,2,1,1,1,1,2,1,1]return = ["Bright sun over hills","soft rain touches green leaves calm","winds carry birds home"]The three consecutive groups total 5, 7, and 5 syllables.
Constraints
1 <= token count <= 2000words.length == syllables.length- Every normalized sentence token appears exactly once in
words. - Every syllable count is positive.
More Faire interview questions
Similar questions at other companies
- Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN
- Longest Substring Without Repeating CharactersNykaa · PHONE SCREENNykaa interview questions
- Longest Substring Without Repeating CharactersIBM · PHONE SCREENIBM interview questions
- Longest Substring Without Repeating CharactersTikTok · PHONE SCREENTikTok interview questions
- Find Word-Multiset WindowsAmazon · PHONE SCREEN
- Longest Substring Without Repeating CharactersCapgemini · PHONE SCREENCapgemini interview questions
- Longest Substring Without Repeating CharactersWex · PHONE SCREEN
- Minimum Window of Required WordsSalesforce · PHONE SCREENSalesforce interview questions
- Longest Substring Without Repeating CharactersRedNote · PHONE SCREEN
- Longest Substring Without Repeating CharactersNetflix · PHONE SCREENNetflix interview questions