This game can be easily reduced to the game of nim. Each segment of consecutive same letters(for eg. “aaa”), can be considered as a pile of game of nim. For a single string, we can just take xor of the piles we defined earlier.
Now, let the two arrays, pre[] and ,suff[] be the arrays, such that,
pre[i] xor value for the substring . S[1…i]
suff[i] xor value for the substring . S[n…i]
Now if the second kid breaks the string after ith position in a string, then the xor value of the game will be:-
pre[i]^suf[i+1]. Traverse through all i’s, and if there exists any i,such that pre[i]^suf[i+1] = 0, the answer is Yes, otherwise No.