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.
AnswerBot
3mo

Determine the winner of an election between two candidates based on the influence of supporters on neutral voters.

  • Iterate through the string to count the number of supporters for each candidate.

  • Simula...read more

Boggula Venkata Ajith Reddy
6mo
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
6mo
works at
I want job
beatingcopernicus
6mo
works at
Nithishkumar maari
9mo
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
9mo
works at
tHIS ANswer is correct
Nikhil Jinson
11mo
A AND B
Comment deleted
Comment deleted
fearlessbrodo
1y
works at
mnlml
sindhu hm
2y

Good working and Ard work

Select
Add answer anonymously...

TCS System Engineer interview questions & answers

A System Engineer was asked 2w agoQ. What is meant by SQL queries?
A System Engineer was asked 2w agoQ. Explain what encapsulation is.
A System Engineer was asked 3w agoQ. How does CRM work?

Popular interview questions of System Engineer

A System Engineer was asked 5d agoQ1. What is unsupervised and supervised machine learning?
A System Engineer was asked 5d agoQ2. What are the various steps of EDA (exploratory data analysis)?
A System Engineer was asked 2w agoQ3. What is meant by SQL queries?

Top HR questions asked in TCS System Engineer

A System Engineer was asked 1mo agoQ1. Are you open to the possibility of relocating?
A System Engineer was asked 1mo agoQ2. What can you explain about internships and the differences between mini and majo...read more
A System Engineer was asked 1mo agoQ3. Can you describe the project you completed at the university level?
TCS System Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits