230. Balanced Bracket Strings
Challenge1000 ms256 MBSolved by 0%
Print how many different balanced strings can be made from n pairs of
brackets.
n = 3 -> ((())) (()()) (())() ()(()) ()()() is 6... no, 5
Count them yourself for n = 3 before writing code. The answer is 5, and if
you found 6 you counted one twice.
Build them by choosing one character at a time. You may open a bracket while you have any left, and you may close one only while more are open than closed. That second rule is what keeps every string valid.
Constraints - `0 ≤ n ≤ 19`
Input
A single line containing one integer n.
Output
Print one integer, the number of balanced strings.
Input3
Output5
Noteis the case worked through in the statement
Input0
Output1
Noteis zero pairs, where the empty string is the one valid arrangement
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution