FastPrepWrap Text at 80 Characters
Problems/Wrap Text at 80 Characters

Wrap Text at 80 Characters

Microsoft logoMicrosoft● MediumFULLTIMEONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Data Scientist/Applied Scientist internship report asks to wrap long text at 80 characters without splitting words or starting lines with spaces. Space normalization, overlong-word handling, interface, and bounds are conventional enrichment.

Given a text string whose words are separated by spaces, wrap it into lines of at most 80 characters without splitting any word.

Ignore leading and trailing spaces and collapse every run of spaces between words to one space. No returned line may begin or end with a space. If one word is longer than 80 characters, place that word alone on a line without splitting it.

Function

wrapText(text: String) → String[]

Examples

Example 1

text = "FastPrep makes interview practice easier"return = ["FastPrep makes interview practice easier"]

The normalized text is shorter than the line limit, so it fits on one line.

Example 2

text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbb c"return = ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbb","c"]

The first two words plus their separating space occupy exactly 80 characters, so the final word starts a new line.

Constraints

  • 0 <= text.length <= 200000
  • text contains printable ASCII characters and spaces.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Rearrange a String So No Neighbors MatchThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Reorganize a StringAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Longest-Match Tokenizer with Unknown SymbolsAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Minimum Nonadjacent Flips for an Alternating Binary StringInfosys · ONSITE INTERVIEWInfosys interview questions
  • Shortest Sequence of Source SubsequencesPinterest · ONSITE INTERVIEWPinterest interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Minimum Removal for Balanced ParenthesesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Choose the Next Hidden-Word GuessFlexport · ONSITE INTERVIEWFlexport interview questions
  • Largest K-Digit SubsequenceGoogle · ONSITE INTERVIEWGoogle interview questions
  • Minimum Remove to Make Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

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)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String[] wrapText(String text) {
      // Write your code here.
    }

}
Checking account…