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
- Find the missing value from the given equation a + b = c
- Find the direction from given string
- Find the Number which contain the digit d
- Find sub-string with given power
- Program to find the initials of a name.
- Find substrings that contain all vowels
- Find whether X exists in Y after jumbling X
- Given two numbers as strings, find if one is a power of other
- Find the maximum subarray XOR in a given array
- Given two strings, find if first string is a subsequence of second
- Find words which are greater than given length k
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.