A balanced bracket sequence is a string consisting only of the characters “(” (opening brackets) and “)” (closing brackets) such that each opening bracket has a “matching” closing bracket, and vice versa. For example, “(())()” is a balanced bracket sequence, whereas “(())(()” and “())(()” are not.
Given two bracket sequences A and B of the same length, we say that A is lexicographically smaller than B (and write A < B) if:
Given a length N and a positive integer M, your task is to find the M-th balanced bracket sequence in the ordering.
You will be given an even integer N, and a positive integer M. It is guaranteed that M will be no more than the number of balanced bracket sequences of length N.
Output the M-th balanced bracket sequence of length N, when ordered lexicographically.