Two players are playing a game where a string str is given. The first player can take the characters at even indices and the second player can take the characters at odd indices. The player which can build the lexicographically smaller string than the other player wins the game. Print the winner of the game, either player A, B or print Tie if its a tie.
Input: str = “geeksforgeeks”
“eeggoss” is the lexicographically smallest
string that player A can get.
“eefkkr” is the lexicographically smallest
string that player B can get.
And B’s string is lexicographically smaller.
Input: str = “abcdbh”
Approach: Create two empty strings str1 and str2 for player A and B respectively. Traverse the original string character by character and for every character whose index is even, append this character in str1 else append this character in str2. Finally sort the generated string in order to get the lexicographically smallest possible string and compare them to find the winner of the game.
Below is the implementation of the above appoach:
- Find the winner of a game where scores are given as a binary string
- Dictionary and counter in Python to find winner of election
- Find winner of an election where votes are represented as candidate names
- Program to implement FLAMES game
- Program to find the initials of a name.
- Find sub-string with given power
- Find the Number which contain the digit d
- Find the missing value from the given equation a + b = c
- Find the direction from given string
- Find whether X exists in Y after jumbling X
- Find substrings that contain all vowels
- Find words which are greater than given length k
- Find k-th character of decrypted string | Set - 2
- Find indices of all occurrence of one string in other
- Find the resulting Colour Combination
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.