FastPrepFind the First Contiguous Haiku
Problems/Find the First Contiguous Haiku

Find the First Contiguous Haiku

Faire logoFaire● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the first contiguous 5-7-5 sequence in a sentence that has punctuation and mixed case, and requires the result as three strings. We added rules for cleaning up the text and for when nothing is found, so that there is one correct selection.

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 <= 2000
  • words.length == syllables.length
  • Every normalized sentence token appears exactly once in words.
  • Every syllable count is positive.

More Faire interview questions

  • Audit Discounted Category AncestorsONSITE INTERVIEW · Seen Oct 2026
  • Maximum Inherited Product DiscountONSITE INTERVIEW · Seen Oct 2026
  • Peak Bike Demand IntervalsONSITE INTERVIEW · Seen Oct 2026

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
See Faire hiring insights
Saved
class Solution {
    public String[] findFirstHaiku(String sentence, String[] words, int[] syllables) {
        // Write your code here.
    }
}
Checking account…