FastPrepGenerate Parentheses
Problems/Generate Parentheses

Generate Parentheses

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft new grad onsite interview. The report names Generate Parentheses but leaves out the full statement, the order and the limits. Our version is about 97% the same as the reported question.

Given n pairs of parentheses, return every well-formed sequence that uses exactly those pairs.

Return the sequences in lexicographic order.

Function

generateParenthesis(n: int) → List<String>

Examples

Example 1

n = 3return = ["((()))","(()())","(())()","()(())","()()()"]

These are all five balanced sequences containing three opening and three closing parentheses, in lexicographic order.

Constraints

  • 1 <= n <= 6

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
  • Insert Addition and Multiplication OperatorsPinterest · ONSITE INTERVIEWPinterest interview questions
  • Enumerate All SubsequencesInfosys · ONSITE INTERVIEWInfosys interview questions
  • Generate ParenthesesAmazon · ONSITE INTERVIEW
  • Maximum Unique-Character Word SubsetMeta · ONSITE INTERVIEWMeta interview questions
  • Generate All Valid Word AbbreviationsSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Phone Keypad Letter CombinationsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Generate Palindromic PermutationsMotive · ONSITE INTERVIEWMotive interview questions
  • Permutations of Character PositionsPeopleStrong · ONSITE INTERVIEWPeopleStrong interview questions
  • Letter Combinations of Phone DigitsCapital One · ONSITE INTERVIEWCapital One 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 List<String> generateParenthesis(int n) {
      // write your code here
    }
}
Checking account…