FastPrepCount Word Break Sentences
Problems/Count Word Break Sentences

Count Word Break Sentences

Meta logoMeta● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The Meta machine learning engineer phone interview asked for the count version of Word Break II. Our version is about 99% the same as the reported question and its linked reference.

Given a lowercase string s and a dictionary wordDict, count the distinct sentences that can be formed by inserting spaces so every resulting word is in the dictionary. The words must cover s in order, without changing or omitting characters. A dictionary word may be reused.

Two sentences are distinct when their word boundaries differ. Return the number of valid sentences, or 0 if no complete segmentation exists. Return only the count; do not construct the sentence strings.

Function

countWordBreakSentences(s: String, wordDict: String[]) → int

Examples

Example 1

s = "catsanddog"wordDict = ["cat","cats","and","sand","dog"]return = 2

There are two segmentations: cats and dog and cat sand dog.

Example 2

s = "pineapplepenapple"wordDict = ["apple","pen","applepen","pine","pineapple"]return = 3

The three word-boundary choices form three valid sentences, including one that reuses apple.

Example 3

s = "catsandog"wordDict = ["cats","dog","sand","and","cat"]return = 0

No sequence of dictionary words covers every character.

Constraints

  • 1 <= s.length <= 20
  • 1 <= wordDict.length <= 1000
  • 1 <= wordDict[i].length <= 10
  • s and every dictionary word contain only lowercase English letters.
  • Dictionary words are unique.
  • The number of valid sentences does not exceed 100000.

More Meta Phone Screen questions

  • Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
  • Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • First Element Greater Than KPHONE SCREEN · Seen Nov 2026
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Longest Palindromic SubstringSiemens · PHONE SCREEN
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
  • Edit DistanceDP World · PHONE SCREEN
  • Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions
  • Word BreakAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Decode WaysThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Edit DistanceAstrotalk · PHONE SCREEN
  • Longest Palindromic SubstringeBay · PHONE SCREENeBay interview questions
  • Count Palindromic SubstringsThe Voleon Group · PHONE SCREEN
  • Generate One-Two Strings with Sum NGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int countWordBreakSentences(String s, String[] wordDict) {
        // Write your code here
    }
}
Checking account…