Loading content...
Given a positive integer n representing the number of bracket pairs available, your task is to generate and return all possible combinations of well-formed (properly balanced and nested) bracket sequences using exactly n pairs of opening '(' and closing ')' brackets.
A bracket sequence is considered well-formed if:
The output should contain all unique valid sequences. The order of sequences in the output does not matter.
n = 3["((()))","(()())","(())()","()(())","()()()"]With 3 bracket pairs, there are exactly 5 distinct ways to arrange them into valid sequences. Each sequence contains 3 opening and 3 closing brackets. For instance, "((()))" represents the most deeply nested form, while "()()()" represents sequential pairs without nesting.
n = 1["()"]With only 1 bracket pair, there is exactly one valid configuration: a single opening followed by a single closing bracket.
n = 2["(())","()()"]With 2 bracket pairs, we can either nest one pair inside the other "(())" or place them sequentially "()()". These are the only two valid configurations.
Constraints