I solved it in the practice mood. And, The test cases are weak .For AAAAAAAAAAABAAAAAAAAAAABAAAAAAAAAAA the answer should be B. But, my previously accepted code printed -1.
"This can’t work for triplets or more because C(N,k)≠2 for N≥3"
Can anyone explain me why is it so?
@p.abhinav : C(n,k) is the number of subsequences of length K in a string of length N. Since we need the longest subsequence that apperars only twice, we need C(n,k) to be equal to 2 which is not possible for n >= 3. That is why we consider only double occurrences of a letter surrounded by other letters.
I was going through some of the contest solutions. Looks like some of the solutions followed a different strategy rather than the one discussed in the editorial. Would be great if anyone shares any other strategy.
And thanks a lot for such a wonderfully explained editorial.
I don’t understand why so much emphasis was given(in the problem statement) on the fact that the strings were generated randomly. I mean why does it matter how the test cases were generated? They appear to us random any way! Does randomness hold any significance here?
What about case- ABABABABABABABABABABABABABABABABAB …! Can someone give proof that in this case there doesn’t exist subsequence of S and appears only twice in it ?
Nice Editorial 
My answers are correct for all test cases … Still I am getting 10 points
… My Submission ID is 9926364 … Can anyone help me ? Thanks in advance
ABAAAAABB : for this case will the answer be ABAAAAAB ? if Yes then what case does it falls under ?
This was a good and tricky problem!
in editorialist’s code when we check for count_a==2 or count_b==2 we should also check that both counts are not 2 simultaneously ie. cases like -> AABB
@glow: Is that really a problem? The solution will still give a correct answer(i.e. “A” in this case).
my bad i thought we have to print longest of such string.
Test cases were weak for sure, my solution did not deserve 36 points ;).
@p.abhinav Eg: aba|bb|aba …notice there’s a doublet in the middle (N=2).
So first sub sequence would be aba|b|aba (using first ‘b’).
and second would be aba|b|aba (using second ‘b’).
However,if our string was aba|bbb|aba…notice the triplet in the middle (N=3),
number of ways to choose k length sub sequence will never be = 2 as C(3,k) = 1 or 3 always for 1<=k<=3; So we’ll get 3 sub sequences of similar kind.
Similarly for N=4,5… which has been generalized in the above eqn.
The string given is random. 
there does exist.
i have corrected string , i have mistakenly put two cosecutive “BB” …! my main point is what if string appear like this REGEX=(“AB”)*
unless u have a substring like “ABBA” or “BAAB” in the string
or it starts with “BBA” or “AAB”
or ends with “ABB” or “BAA”
the answer is -1
ok .i got first part very well , but my question is , why there does not exist string in given case(my case(AB)*) .! do you have any proof for it…?