Given two strings ‘A’ and ‘B’ of equal length. Two players play a game where they both pick a character from their respective strings (First picks from A and second from B) and put into a third string (which is initially empty). The player that can make the third string palindrome, is winner. If first player makes palindrome first then print ‘A’, else ‘B’. If strings get empty and no one is able to make a palindrome, then print ‘B’.
Input : A = ab B = ab Output : B First player puts 'a' (from string A) Second player puts 'a' (from string B) which make palindrome. The result would be same even if A picks 'b' as first character. Input : A = aba B = cde Output : A Input : A = ab B = cd Output : B None of the string will be able to make a palindrome (of length > 1) in any situation. So B will win.
After taking few examples, we can observe that ‘A’ (or first player) can only win when it has a character that appears more than once and not present in ‘B’.
This article is contributed by Akshay Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check whether frequency of characters in a string makes Fibonacci Sequence
- Count all palindrome which is square of a palindrome
- Find Bit whose minimum sequence flips makes all bits same
- Check if there exists any sub-sequence in a string which is not palindrome
- Meta Strings (Check if two strings can become same after a swap in one string)
- Longest string which is prefix string of at least two strings
- Count of three non-overlapping sub-strings which on concatenation forms a palindrome
- Count of strings in the first array which are smaller than every string in the second array
- Find a string in lexicographic order which is in between given two strings
- Given two strings, find if first string is a subsequence of second
- Largest palindrome which is product of two N-digit numbers : Set 2
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Check if a linked list of strings forms a palindrome
- Find the player who rearranges the characters to get a palindrome string first
- Count All Palindrome Sub-Strings in a String | Set 2
- Count All Palindrome Sub-Strings in a String | Set 1
- Count number of rotated strings which have more number of vowels in the first half than second half
- Count subsequences in first string which are anagrams of the second string
- Most frequent word in first String which is not present in second String