Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

103. Generate Parentheses

MediumDay 31 of 60Recursion & Backtracking

Given an integer n, return all strings made of exactly n pairs of parentheses that are well formed (every opening bracket is closed in the right order). The strings may be returned in any order.

Example 1
Input: n = 3
Output: ["((()))","(()())","(())()","()(())","()()()"]
Example 2
Input: n = 1
Output: ["()"]
Constraints
  • 1 <= n <= 8
Hints
Frequently asked at: Google, Amazon, Microsoft, Meta
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min