FastPrepGenerate All String Permutations
Problems/Generate All String Permutations

Generate All String Permutations

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft intern onsite interview. The report asks for all permutations of a string. It leaves out how to treat repeated letters, the output order and the limits. Our version is about 92% the same as the reported question.

Given a string s whose characters are distinct lowercase English letters, return every permutation of its characters.

Return the permutations in lexicographic order.

Function

generatePermutations(s: String) → String[]

Examples

Example 1

s = "abc"return = ["abc","acb","bac","bca","cab","cba"]

All six arrangements of the three distinct characters are returned in lexicographic order.

Example 2

s = "ba"return = ["ab","ba"]

The input order does not determine the output order; the two permutations are sorted lexicographically.

Example 3

s = "x"return = ["x"]

A one-character string has exactly one permutation.

Constraints

  • 1 <= s.length <= 8
  • s contains distinct lowercase English letters.

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

  • Generate Strings of Length at Least ThreeMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
  • String Permutations in Custom Character OrderWex · OA · PHONE SCREEN
  • Permutations IILinkedIn · PHONE SCREENLinkedIn interview questions
  • Unique String PermutationsAmazon · PHONE SCREEN
  • Generate All String PermutationsBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Travelers per Consecutive City TripletUber · ONSITE INTERVIEWUber interview questions
  • Generate All Permutations of a NumberFleetx · ONSITE INTERVIEW
  • Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
  • Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Response Time Stats by URL PatternGusto · ONSITE INTERVIEWGusto interview questions

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)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String[] generatePermutations(String s) {
      // write your code here
    }
}
Checking account…