FastPrepGenerate Parentheses
Problems/Generate Parentheses

Generate Parentheses

The Walt Disney Company logoThe Walt Disney Company● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interviewer asked: "Generate Parentheses (LeetCode 22)."

The report does not give bounds or an output order. Here, n is from 1 to 8 and results are in lexicographic order.

The judged task matches the report at about 85%.

Given an integer n, return every balanced string made from exactly n pairs of parentheses.

A string is balanced when each opening parenthesis has a later matching closing parenthesis and no prefix has more closing parentheses than opening parentheses.

Return each string once, in lexicographic order. The character ( comes before ).

Function

generateParenthesis(n: int) → List<String>

Examples

Example 1

n = 1return = ["()"]

The only balanced string with one pair is ().

Example 2

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

There are five balanced strings with three pairs. Each prefix has at least as many opening parentheses as closing parentheses. The strings are listed in lexicographic order.

Constraints

  • 1 <= n <= 8

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public List<String> generateParenthesis(int n) {
        // Write your code here
    }
}
Checking account…