You are given an array of characters 'G' of length 'N', where each character represents the outcome of a game. The character 'A' indicates a win for Team A, and the character 'B' indicates a win for Team B.
Your task is to count the number of wins for each team and return the team that has won the most games. If both teams have won the same number of games, return "Tie".
Let 'N' = 5, 'G' = ['A', 'B', 'A', 'A', 'B'].
Team A has won 3 games, and Team B has won 2 games.
Therefore, the answer is "A".
The first line contains an integer 'N', the number of games.
The second line contains the array of characters 'G' of length 'N', representing the game outcomes.
Output Format :
Return a string representing the team with the most wins ("A" or "B") or "Tie" if both teams have the same number of wins.
Note :
You don’t need to print anything. Just implement the given function.
1 <= 'N' <= 10^5
Each character in 'G' will be either 'A' or 'B'.
Time Limit: 1 sec
3
A B A
A
The array of game outcomes 'G' is ['A', 'B', 'A'], and the number of games 'N' is 3.
By iterating through the array 'G', we find that Team A has won 2 games and Team B has won 1 game.
Since Team A has won more games than Team B, the answer is "A".
4
B B A A
Tie
Traverse the array and keep track of the number of wins for each team.
Approach:
Algorithm:
O(N), where 'N' is the number of games in the array 'G'.
We iterate through the array 'G' once to count the wins for each team. Thus, the overall time complexity is of the order O(N).
O(1).
We use a constant amount of extra space to store the win counts for Team A ('count_A') and Team B ('count_B'). Thus, the overall space complexity is of the order O(1).