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.
- Check whether frequency of characters in a string makes Fibonacci Sequence
- Count All Palindrome Sub-Strings in a String | Set 1
- Count All Palindrome Sub-Strings in a String | Set 2
- Check if a linked list of strings forms a palindrome
- Meta Strings (Check if two strings can become same after a swap in one string)
- Check if a given string is a rotation of a palindrome
- Check if it is possible to create a palindrome string from given N
- Check if a string is palindrome in C using pointers
- C Program to Check if a Given String is Palindrome
- Check if any anagram of a string is palindrome or not
- Python program to check if a string is palindrome or not
- Check if there exists any sub-sequence in a string which is not palindrome
- Recursive function to check if a string is palindrome
- Java program to check whether a string is a Palindrome
- Check if string can be rearranged so that every Odd length Substring is Palindrome