If ‘S’ is a regular sequence, then (S) is also regular.
If ‘A’ and ‘B’ represent two regular sequences, then their concatenation ‘AB’ is also regular.
Therefore, the sequences (), ()() and (())() are regular, while ()(, ) and ))() are non-regular.
‘(‘ is considered lexicographically smaller than ‘)’.
Two subsequences are distinct if they differ at least at one of the indexes. E.g. ‘))’ and ‘((‘ are distinct whereas ‘((‘ and ‘((‘ are not.
N = 5
S = ()
K = 2
Explanation :
All possible subsequences of the given sequence are : ‘(‘ , ‘)’ and ‘()’.
The non-regular subsequences among these are : ‘(‘ and ‘)’.
Of these the lexicographically ‘2nd’ subsequence is ‘)’.
Hence, final result = ‘)’.
The first line contains an integer 'T' which denotes the number of test cases to be run. Then the test cases follow.
The first line of each test case contains two integers ‘N’ and ‘K’.
The second line of each test case contains a string ‘S’ of length ‘N’.
For each test case, print a string denoting the lexicographically ‘Kth’ non-regular subsequence of string ‘S’.
Print the output of each test case in a new line.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10^5
1 <= K <= 10^9
S[i] = ‘(‘ or S[i] = ‘)’.
Time Limit : 1 sec
Algorithm :
Approach :
Algorithm :
1-3 Palindrome
Ninja And The Strictly Increasing Array
Maximize
Search Pattern (KMP - Algorithm)
Search Pattern (KMP - Algorithm)
Search Pattern (KMP - Algorithm)
RNA or DNA