FastPrepWord Break II: All Sentences
Problems/Word Break II: All Sentences

Word Break II: All Sentences

Microsoft logoMicrosoft● HardFULLTIMEINTERNPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft phone screen. The report names Word Break II but does not give the full statement. Here the results come out sorted, and we set clear limits.

Our version is about 95% the same as the reported question.

Given a nonempty string s and an array of distinct words wordDict, return every way to split the entire string into dictionary words.

Represent each split as a sentence with exactly one space between adjacent words. Do not add a leading or trailing space. A dictionary word may be used more than once.

Return the distinct sentences in lexicographically increasing order. If no complete split exists, return an empty array.

Function

wordBreakSentences(s: String, wordDict: String[]) → String[]

Examples

Example 1

s = "redblue"wordDict = ["red","blue","redblue"]return = ["red blue","redblue"]

Either use the two words red and blue, or use the single word redblue. The sentence containing a space sorts first.

Example 2

s = "redgreen"wordDict = ["red","blue"]return = []

The prefix red is valid, but the remaining green cannot be covered by dictionary words.

Example 3

s = "aa"wordDict = ["a","aa"]return = ["a a","aa"]

The word a may be reused, so both a a and aa are valid complete sentences.

Constraints

  • 1 <= s.length <= 20.
  • 1 <= wordDict.length <= 1000.
  • 1 <= wordDict[i].length <= 10.
  • s and every dictionary word contain only lowercase English letters.
  • The dictionary words are distinct.
  • The sum of the lengths of all returned sentences, counting spaces, is at most 10^5.

More Microsoft Phone Screen questions

  • Config Store with Priority OverridesPHONE SCREEN · Seen Nov 2026
  • Corporation Reporting LinesPHONE SCREEN · Seen Oct 2026
  • Random Forest Classifier from ScratchPHONE SCREEN · Seen Oct 2026
  • Least Recently Used CacheOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Greedy and Beam Sentence DecodingPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Top K Frequent ElementsPHONE SCREEN · Seen Sep 2026
  • 3SumPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Arithmetic Expression EvaluatorPHONE SCREEN · Seen Sep 2026
  • Employee Hierarchy Cycle and Depth AnalysisPHONE SCREEN · Seen Sep 2026
  • Most Visited String SectorsPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Balanced Parentheses with Sequential Left DeletionsGoogle · PHONE SCREENGoogle interview questions
  • Word Break IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Word Break IIWex · PHONE SCREEN
  • Word Break IIInMobi · PHONE SCREENInMobi interview questions
  • Word Break IIBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Palindrome PartitioningLondon Stock Exchange · PHONE SCREENLondon Stock Exchange interview questions
  • All Palindrome PartitionsExpedia · OAExpedia interview questions
  • Minimum Insertion Steps to Make a String PalindromeInfosys · ONSITE INTERVIEWInfosys interview questions
  • Wildcard MatchingTripjack · ONSITE INTERVIEWTripjack interview questions
  • All Balanced Strings from Minimum Parenthesis InsertionsRubrik · ONSITE INTERVIEWRubrik interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String[] wordBreakSentences(String s, String[] wordDict) {
        // Write your solution here
    }
}
Checking account…