An n pair parentheses sequence is a string of length 2n made of n opening brackets ( and n closing brackets ).
A valid parentheses sequence is defined as follows.
You can repeat erasing an adjacent pair () until the string becomes empty.
For example, (()) is valid. Erase the characters at positions 2 and 3 to get (), then erase that pair to get the empty string. )()( is not valid. After erasing the characters at positions 2 and 3 you are left with )(, and nothing more can be erased.
Collect every valid n pair parentheses sequence and sort them in lexicographic order, then find the k-th one. In the comparison ( comes before ).
For n equal to 3, the valid sequences in lexicographic order are:
((()))
(()())
(())()
()(())
()()()