Well-parenthesized strings are defined using the following rules:
- The empty string is well-parenthesized.
- If S is a well-parenthesized string, then (S) is a well-parenthesized string.
- If S and T are well-parenthesized strings, then ST is a well-parenthesized string.
- Every well-parenthesized string can be created using the previous rules only.
In this problem we will deal with the complement of this set of strings: The strings that consist only of the characters '(' and ')', but are not well-parenthesized. We will call these strings mismatched.
You are given an int N and a long K. All mismatched strings of length N can be ordered lexicographically, and numbered sequentially, starting with zero. Return the string that will get the number K in this order. If there is no such string, return the empty string instead.
|