Election Winner Determination
In an ongoing election between two candidates A and B, there is a queue of voters that includes supporters of A, supporters of B, and neutral voters. Neutral voters have the power to swing the election results based on which candidate influences them to their side.
Voting Influence Mechanics:
1. The queue is represented by the characters { '-', 'A', 'B' }, where '-' is a neutral voter, 'A' is a supporter of A, and 'B' is a supporter of B.
2. Supporters of A can only move left, influencing neutral voters.
3. Supporters of B can only move right, influencing neutral voters.
4. Movement happens simultaneously for both supporters of A and B.
5. If a supporter of A reaches a neutral voter before a supporter of B, that voter supports A.
6. Conversely, if a supporter of B reaches a neutral voter first, that voter supports B.
7. If both reach a neutral voter at the same time, the voter remains neutral.
8. Determine the election winner: A wins if they have more supporters, B wins if they have more supporters, or it's a Coalition if it's a tie.
Example:
Input:
String: "B--A-"
Output:
B
Explanation:
In the given string, B can influence more neutral voters compared to A. Thus, B has a total of 3 supporters, outnumbering A's 2 supporters.
Input:
The first line contains an integer T, the number of test cases.
Each of the next T lines contains a string of characters 'A', 'B', and '-'.
Output:
For each test case, print 'A' if A wins, 'B' if B wins, or 'Coalition' if it's a tie, each on a new line.
Constraints:
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 104
- No test case with all votes neutral.
Additional Notes:
You are required to implement the function; printing is handled elsewhere.
Boggula Venkata Ajith Reddy
2mo
Hamburger Menu AmbitionBox Logo Search designation Asked inTCS,System Engineer Who Won the Election??? Elections are going on, and there are two candidates A and B, contesting with each other. There i...read more
brucewayne
2mo
works at
I want job
beatingcopernicus
2mo
works at
Nithishkumar maari
5mo
To determine who won the election based on the voters' preferences, you can simulate how neutral voters cast their votes by observing the influence of the supporters of candidates A and B
fearlessbrodo
5mo
works at
tHIS ANswer is correct
Nikhil Jinson
7mo
A AND B
Comment deleted
Comment deleted
fearlessbrodo
1y
works at
mnlml
sindhu hm
1y
Good working and Ard work
Add answer anonymously...
Top TCS System Engineer interview questions & answers
Popular interview questions of System Engineer
Top HR questions asked in TCS System Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app