Loading...
Loading...
Loading...
Print every balanced string made of n pairs of round brackets, one per line, in dictionary order (an opening bracket comes before a closing one). A string is balanced when every closing bracket matches an earlier opening one.
Example
Input
2
Output
(()) ()()
Two strings.
Try the problem first. Open one hint at a time.
Count how many opening and closing brackets are used so far.
Add an opening bracket while fewer than n are used, and a closing one only while closed is less than opened.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor