I attended a programming competition(it has ended now). I don't know why my solution is giving WA, I read the editorial, saw other people solution but unable to find a flaw in my solution. Obviously I am missing somewhere. Please help!
If the pattern is non regular, answer is the same. Otherwise answer would be of length 1 less than the original pattern. Now the 1st lexicographic-ally smallest pattern can be obtained by removing one of the ')' from the first chunk(continuous sequence) of ')' in original pattern. 2nd lexicographic-ally smallest pattern can be obtained by removing one of the ')' from the second(if any) chunk(continuous sequence) of ')' in original pattern.And so on. And then say there are 'x' chunks of ')'. And we need to find kth lexicographic-ally pattern such that (k>x). For this case we move from backward, so for (x+1)th smallest pattern we remove '(' from first chunk of '(' (moving backward to front), for (x+2)nd we remove '(' from second chunk, and so on. The same logic is explained in tutorial here.