Loading...
Loading...
Loading...
A label printer needs every valid bracket code that uses exactly n pairs of round brackets. Print them in dictionary order, where ( comes before ), one per line.
Example 1
Input
2
Output
(()) ()()
Two codes.
Example 2
Input
1
Output
()
Try the problem first. Open one hint at a time.
Build the string one character at a time. You can add ( while fewer than n are used.
You can add ) only when more ( than ) are already placed.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor