Write a program to find top two candidates winning the election.
You are the administrator of an election system. The back end is offline and election results are requested.
All votes are logged to vote.log(stream). We want to see results in real time.
- A single voter can vote for 3 candidates.
- A voter cannot vote for the same candidate more than once.
Using the log find the top 5 candidates and detect fraud by printing the voter id and not counting the vote.
Fraud is candidate voting more than 3 times and/or a candidate more than once.
@GG Thanks for the interesting question. Here are my thoughts:
- Use a Map<Voter, Integer> to track how many candidates a voter voted. If < 3, accept this vote, otherwise, deny and print out this voter as fraud.
- Use a Map<Candidate, Integer> to track how many tickets each candidate got.
- Use a Heap<Map.Entry<Candidate, Integer>> to monitor the top 2 candidates.